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));
}
const updateNodePositions: UpdateNodePositions = (nodeDragItems, dragging = false) => {
store.nodes.update((nds) => {
return nds.map((node) => {
const nodeDragItem = (nodeDragItems as Array<Node | NodeDragItem>).find(
(ndi) => ndi.id === node.id
);
const updateNodePositions: UpdateNodePositions = (nodeDragItems, _, dragging = false) => {
const nodeLookup = get(store.nodeLookup);
if (nodeDragItem) {
return {
...node,
dragging,
position: nodeDragItem.position,
computed: {
...node.computed,
positionAbsolute: nodeDragItem.computed?.positionAbsolute
},
[internalsSymbol]: node[internalsSymbol]
};
}
nodeDragItems.forEach((nodeDragItem) => {
const node = nodeLookup.get(nodeDragItem.id);
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>) {