chore(react/svelte): rename nodes/edges to initialNodes/initialEdges for Provider comp

This commit is contained in:
moklick
2023-10-09 17:12:49 +02:00
parent afa6365e12
commit d062214536
3 changed files with 28 additions and 14 deletions

View File

@@ -8,21 +8,26 @@ import type { ReactFlowState, Node, Edge } from '../../types';
function ReactFlowProvider({
children,
nodes,
edges,
width,
height,
initialNodes,
initialEdges,
initialWidth,
initialHeight,
}: {
children: ReactNode;
nodes?: Node[];
edges?: Edge[];
width?: number;
height?: number;
initialNodes?: Node[];
initialEdges?: Edge[];
initialWidth?: number;
initialHeight?: number;
}) {
const storeRef = useRef<UseBoundStoreWithEqualityFn<StoreApi<ReactFlowState>> | null>(null);
if (!storeRef.current) {
storeRef.current = createRFStore({ nodes, edges, width, height });
storeRef.current = createRFStore({
nodes: initialNodes,
edges: initialEdges,
width: initialWidth,
height: initialHeight,
});
}
return <Provider value={storeRef.current}>{children}</Provider>;

View File

@@ -6,10 +6,17 @@
type $$Props = SvelteFlowProviderProps;
export let nodes: $$Props['nodes'] = undefined;
export let edges: $$Props['edges'] = undefined;
export let initialNodes: $$Props['initialNodes'] = undefined;
export let initialEdges: $$Props['initialEdges'] = undefined;
export let initialWidth: $$Props['initialWidth'] = undefined;
export let initialHeight: $$Props['initialHeight'] = undefined;
const store = createStore({ nodes, edges });
const store = createStore({
nodes: initialNodes,
edges: initialEdges,
width: initialWidth,
height: initialHeight
});
setContext(key, {
getStore: () => store

View File

@@ -1,6 +1,8 @@
import type { Edge, Node } from '$lib/types';
export type SvelteFlowProviderProps = {
nodes?: Node[];
edges?: Edge[];
initialNodes?: Node[];
initialEdges?: Edge[];
initialWidth?: number;
initialHeight?: number;
};