diff --git a/src/store/stateStore.ts b/src/store/stateStore.ts index 1d3e6ebd..ec255c91 100644 --- a/src/store/stateStore.ts +++ b/src/store/stateStore.ts @@ -178,7 +178,7 @@ export default (id: string, preloadedState: FlowState) => { const { nodes, edges } = parseElements(elements, this.elements, this.nodeExtent) this.elements = [...this.elements, ...nodes, ...edges] }, - async setState(state) { + setState(state) { if (typeof state.panOnScroll !== 'undefined') this.panOnScroll = state.panOnScroll if (typeof state.panOnScrollMode !== 'undefined') this.panOnScrollMode = state.panOnScrollMode if (typeof state.panOnScrollSpeed !== 'undefined') this.panOnScrollSpeed = state.panOnScrollSpeed @@ -206,11 +206,15 @@ export default (id: string, preloadedState: FlowState) => { if (typeof state.multiSelectionKeyCode !== 'undefined') this.multiSelectionKeyCode = state.multiSelectionKeyCode if (typeof state.snapToGrid !== 'undefined') this.snapToGrid = state.snapToGrid if (typeof state.snapGrid !== 'undefined') this.snapGrid = state.snapGrid - if (typeof !this.isReady) await until(() => this.d3Zoom).not.toBeUndefined() - if (typeof state.maxZoom !== 'undefined') this.setMaxZoom(state.maxZoom) - if (typeof state.minZoom !== 'undefined') this.setMinZoom(state.minZoom) - if (typeof state.translateExtent !== 'undefined') this.setTranslateExtent(state.translateExtent) - if (typeof state.nodeExtent !== 'undefined') this.setNodeExtent(state.nodeExtent) + if (typeof !this.isReady) + until(() => this.d3Zoom) + .not.toBeUndefined() + .then(() => { + if (typeof state.maxZoom !== 'undefined') this.setMaxZoom(state.maxZoom) + if (typeof state.minZoom !== 'undefined') this.setMinZoom(state.minZoom) + if (typeof state.translateExtent !== 'undefined') this.setTranslateExtent(state.translateExtent) + if (typeof state.nodeExtent !== 'undefined') this.setNodeExtent(state.nodeExtent) + }) }, }, }) diff --git a/src/types/store.ts b/src/types/store.ts index adef6c53..9991b307 100644 --- a/src/types/store.ts +++ b/src/types/store.ts @@ -89,7 +89,7 @@ export interface FlowActions { setConnectionNodeId: (payload: SetConnectionId) => void setInteractive: (isInteractive: boolean) => void addElements: (elements: Elements) => void - setState: (state: FlowOptions) => Promise + setState: (state: FlowOptions) => void } export interface FlowGetters { diff --git a/src/utils/store.ts b/src/utils/store.ts index 20a3ca92..a16de395 100644 --- a/src/utils/store.ts +++ b/src/utils/store.ts @@ -22,6 +22,8 @@ export const initialState = (): FlowState => ({ }, transform: [0, 0, 1], elements: [], + nodeTypes: [], + edgeTypes: [], selectedElements: undefined, selectedNodesBbox: { x: 0, y: 0, width: 0, height: 0 },