refactored updateNodePositions in svelte

This commit is contained in:
peterkogo
2024-01-23 18:16:05 +01:00
parent 1bd71af135
commit c3104f1fbb
+14 -20
View File
@@ -63,29 +63,23 @@ export function createStore({
store.edges.set(addEdgeUtil(edgeParams, edges)); store.edges.set(addEdgeUtil(edgeParams, edges));
} }
const updateNodePositions: UpdateNodePositions = (nodeDragItems, dragging = false) => { const updateNodePositions: UpdateNodePositions = (nodeDragItems, _, dragging = false) => {
store.nodes.update((nds) => { const nodeLookup = get(store.nodeLookup);
return nds.map((node) => {
const nodeDragItem = (nodeDragItems as Array<Node | NodeDragItem>).find(
(ndi) => ndi.id === node.id
);
if (nodeDragItem) { nodeDragItems.forEach((nodeDragItem) => {
return { const node = nodeLookup.get(nodeDragItem.id);
...node,
dragging,
position: nodeDragItem.position,
computed: {
...node.computed,
positionAbsolute: nodeDragItem.computed?.positionAbsolute
},
[internalsSymbol]: node[internalsSymbol]
};
}
return node; if (node) {
}); node.position = nodeDragItem.position;
node.dragging = dragging;
node.computed = {
...node.computed,
positionAbsolute: nodeDragItem.computed?.positionAbsolute
};
}
}); });
store.nodes.set(get(store.nodes));
}; };
function updateNodeDimensions(updates: Map<string, NodeDimensionUpdate>) { function updateNodeDimensions(updates: Map<string, NodeDimensionUpdate>) {