chore(store): cleanup
This commit is contained in:
@@ -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];
|
||||||
|
|
||||||
|
|||||||
@@ -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';
|
||||||
|
|
||||||
|
|||||||
@@ -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>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user