chore(store): cleanup

This commit is contained in:
moklick
2023-12-13 17:05:13 +01:00
parent 99a422f9f1
commit 46d42e7642
4 changed files with 14 additions and 10 deletions
+4 -1
View File
@@ -25,7 +25,10 @@ const getInitialState = ({
} = {}): ReactFlowStore => { } = {}): ReactFlowStore => {
const nodeLookup = new Map(); const nodeLookup = new Map();
const connectionLookup = updateConnectionLookup(new Map(), edges); const connectionLookup = updateConnectionLookup(new Map(), edges);
const nextNodes = adoptUserProvidedNodes(nodes, nodeLookup, { nodeOrigin: [0, 0], elevateNodesOnSelect: false }); const nextNodes = adoptUserProvidedNodes(nodes, nodeLookup, {
nodeOrigin: [0, 0],
elevateNodesOnSelect: false,
});
let transform: Transform = [0, 0, 1]; let transform: Transform = [0, 0, 1];
-2
View File
@@ -11,8 +11,6 @@ import {
updateConnectionLookup, updateConnectionLookup,
type Viewport, type Viewport,
type PanZoomInstance, type PanZoomInstance,
type Viewport,
type PanZoomInstance,
type ConnectionLookup type ConnectionLookup
} from '@xyflow/system'; } from '@xyflow/system';
+1 -1
View File
@@ -43,7 +43,7 @@ export type NodeBase<T = any, U extends string | undefined = string | undefined>
/** Holds a reference to the original node object provided by the user /** Holds a reference to the original node object provided by the user
* (which may lack some fields, like `computed` or `[internalSymbol]`. Used * (which may lack some fields, like `computed` or `[internalSymbol]`. Used
* as an optimization to avoid certain operations. */ * as an optimization to avoid certain operations. */
userProvidedNode: WeakRef<NodeBase>; userProvidedNode: NodeBase<T, U>;
}; };
}; };
+9 -6
View File
@@ -80,7 +80,10 @@ export function adoptUserProvidedNodes<NodeType extends NodeBase>(
const nextNodes = nodes.map((n) => { const nextNodes = nodes.map((n) => {
const currentStoreNode = tmpLookup.get(n.id); const currentStoreNode = tmpLookup.get(n.id);
if (n === currentStoreNode?.[internalsSymbol]?.userProvidedNode.deref()) return currentStoreNode; if (n === currentStoreNode?.[internalsSymbol]?.userProvidedNode) {
nodeLookup.set(n.id, currentStoreNode);
return currentStoreNode;
}
const node: NodeType = { const node: NodeType = {
...options.defaults, ...options.defaults,
@@ -103,7 +106,7 @@ export function adoptUserProvidedNodes<NodeType extends NodeBase>(
value: { value: {
handleBounds: currInternals?.handleBounds, handleBounds: currInternals?.handleBounds,
z, z,
userProvidedNode: new WeakRef(n), userProvidedNode: n,
}, },
}); });
@@ -144,14 +147,14 @@ function calculateXYZPosition<NodeType extends NodeBase>(
); );
} }
export function updateNodeDimensions( export function updateNodeDimensions<NodeType extends NodeBase>(
updates: Map<string, NodeDimensionUpdate>, updates: Map<string, NodeDimensionUpdate>,
nodes: NodeBase[], nodes: NodeType[],
nodeLookup: Map<string, NodeBase>, nodeLookup: Map<string, NodeType>,
domNode: HTMLElement | null, domNode: HTMLElement | null,
nodeOrigin?: NodeOrigin, nodeOrigin?: NodeOrigin,
onUpdate?: (id: string, dimensions: Dimensions) => void onUpdate?: (id: string, dimensions: Dimensions) => void
): NodeBase[] | null { ): NodeType[] | null {
const viewportNode = domNode?.querySelector('.xyflow__viewport'); const viewportNode = domNode?.querySelector('.xyflow__viewport');
if (!viewportNode) { if (!viewportNode) {