Browse Source

fix: merging data error when removing/moving multiple nodes/edges

master
smallstonesk 4 years ago
parent
commit
1f09df49b2
  1. 24
      packages/core/src/mods/flowChart/registerServerStorage.ts

24
packages/core/src/mods/flowChart/registerServerStorage.ts

@ -17,26 +17,28 @@ const validate = (type: string, data: any) => {
} }
}; };
const enqueue = (type: string, actionType: ActionType, data: any) => { const enqueue = (cellType: string, actionType: ActionType, data: any) => {
if (!validate(type, data)) { if (!validate(cellType, data)) {
return; return;
} }
const foundIndex = memQueue.findIndex( const foundIndex = memQueue.findIndex((item) => (
(item) => item.type === type && item.actionType === actionType item.type === cellType &&
); item.actionType === actionType &&
item.data.id === data.id
));
if (foundIndex > -1) { if (foundIndex > -1) {
const deleted = memQueue.splice(foundIndex, 1)[0]; const deleted = memQueue.splice(foundIndex, 1)[0];
data = merge(deleted, data); merge(deleted.data, data);
} }
memQueue.push({ type, actionType, data }); memQueue.push({ type: cellType, actionType, data });
}; };
let modifyActionTimer = -1; let modifyActionTimer: number = -1;
const save = (flowChart: Graph, type: string, actionType: ActionType, data: any) => { const save = (flowChart: Graph, cellType: string, actionType: ActionType, data: any) => {
enqueue(type, actionType, data); enqueue(cellType, actionType, data);
clearTimeout(modifyActionTimer); clearTimeout(modifyActionTimer);
modifyActionTimer = setTimeout(() => { modifyActionTimer = window.setTimeout(() => {
const pushedActions = memQueue.slice(0); const pushedActions = memQueue.slice(0);
if (pushedActions.length > 0) { if (pushedActions.length > 0) {
flowChart.trigger('graph:change:modify'); flowChart.trigger('graph:change:modify');

Loading…
Cancel
Save