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
@@ -8,21 +8,26 @@ import type { ReactFlowState, Node, Edge } from '../../types';
function ReactFlowProvider({ function ReactFlowProvider({
children, children,
nodes, initialNodes,
edges, initialEdges,
width, initialWidth,
height, initialHeight,
}: { }: {
children: ReactNode; children: ReactNode;
nodes?: Node[]; initialNodes?: Node[];
edges?: Edge[]; initialEdges?: Edge[];
width?: number; initialWidth?: number;
height?: number; initialHeight?: number;
}) { }) {
const storeRef = useRef<UseBoundStoreWithEqualityFn<StoreApi<ReactFlowState>> | null>(null); const storeRef = useRef<UseBoundStoreWithEqualityFn<StoreApi<ReactFlowState>> | null>(null);
if (!storeRef.current) { 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>; return <Provider value={storeRef.current}>{children}</Provider>;
@@ -6,10 +6,17 @@
type $$Props = SvelteFlowProviderProps; type $$Props = SvelteFlowProviderProps;
export let nodes: $$Props['nodes'] = undefined; export let initialNodes: $$Props['initialNodes'] = undefined;
export let edges: $$Props['edges'] = 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, { setContext(key, {
getStore: () => store getStore: () => store
@@ -1,6 +1,8 @@
import type { Edge, Node } from '$lib/types'; import type { Edge, Node } from '$lib/types';
export type SvelteFlowProviderProps = { export type SvelteFlowProviderProps = {
nodes?: Node[]; initialNodes?: Node[];
edges?: Edge[]; initialEdges?: Edge[];
initialWidth?: number;
initialHeight?: number;
}; };