From 758f4f23ff5434847188f3e87ffbcfa127eca60c Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Sun, 12 Dec 2021 23:46:17 +0100 Subject: [PATCH] refactor(store): Rename isReady to paneReady Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com> --- src/container/ZoomPane/ZoomPane.vue | 2 +- src/store/actions.ts | 2 +- src/store/getters.ts | 6 +++--- src/store/state.ts | 3 +-- src/store/store.ts | 9 +++------ src/types/store.ts | 5 ++--- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/container/ZoomPane/ZoomPane.vue b/src/container/ZoomPane/ZoomPane.vue index 798025f3..ce8577c1 100644 --- a/src/container/ZoomPane/ZoomPane.vue +++ b/src/container/ZoomPane/ZoomPane.vue @@ -187,7 +187,7 @@ onMounted(() => { ) }) nextTick(async () => { - store.isReady = true + store.paneReady = true // if ssr we can't wait for dimensions, they'll never really exist const window = useWindow() diff --git a/src/store/actions.ts b/src/store/actions.ts index 8f4979b4..d3f49141 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -181,7 +181,7 @@ export default (state: FlowState, getters: FlowGetters): FlowActions => { if (typeof opts.snapToGrid !== 'undefined') state.snapToGrid = opts.snapToGrid if (typeof opts.snapGrid !== 'undefined') state.snapGrid = opts.snapGrid if (typeof opts.nodeExtent !== 'undefined') state.nodeExtent = opts.nodeExtent - if (!state.isReady) + if (!state.paneReady) until(() => state.d3Zoom) .not.toBeUndefined() .then(() => { diff --git a/src/store/getters.ts b/src/store/getters.ts index 790fee53..a29b4097 100644 --- a/src/store/getters.ts +++ b/src/store/getters.ts @@ -22,7 +22,7 @@ export default (state: FlowState): FlowGetters => { }) const getNodes = computed(() => { - if (state.isReady && state.dimensions.width && state.dimensions.height) { + if (state.paneReady && state.dimensions.width && state.dimensions.height) { const nodes = state.nodes.filter((n) => !n.hidden) return state.onlyRenderVisibleElements ? nodes && @@ -43,8 +43,8 @@ export default (state: FlowState): FlowGetters => { }) const getEdges = computed(() => { - if (state.isReady && state.dimensions.width && state.dimensions.height) { - if (!state.onlyRenderVisibleElements) return state.edges + if (state.paneReady && state.dimensions.width && state.dimensions.height) { + if (!state.onlyRenderVisibleElements) return state.edges.filter((e) => !e.hidden) else return state.edges.filter( (e) => diff --git a/src/store/state.ts b/src/store/state.ts index 3ca61b83..27f7f888 100644 --- a/src/store/state.ts +++ b/src/store/state.ts @@ -16,11 +16,10 @@ export const defaultEdgeTypes: DefaultEdgeTypes = { } export default (): FlowState => ({ - elements: [], nodes: [], edges: [], - isReady: false, + paneReady: false, instance: undefined, dimensions: { diff --git a/src/store/store.ts b/src/store/store.ts index ff48bbf7..83b556b5 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -1,7 +1,7 @@ import useState from './state' import useActions from './actions' import useGetters from './getters' -import { FlowExportObject, FlowHooksOn, FlowOptions, FlowState, Store } from '~/types' +import { FlowExportObject, FlowHooksOn, FlowOptions, FlowState, GraphEdge, GraphNode, Store } from '~/types' import { onLoadToObject } from '~/utils' const useFlowStore = (id: string, preloadedState: FlowState): Store => { @@ -30,7 +30,6 @@ export default (options?: FlowOptions) => { let storedState = ref() const initial = useState() const storageKey = options?.id ?? `vue-flow-${id++}` - delete options?.id const preloadedState = { ...initial, ...(options as FlowState), @@ -38,10 +37,8 @@ export default (options?: FlowOptions) => { if (withStorage) { storedState = useStorage(storageKey, { edges: [], nodes: [], position: [0, 0], zoom: 0 }) if (storedState.value) { - preloadedState.elements = - storedState.value.nodes || storedState.value.edges - ? [...storedState.value.nodes, ...storedState.value.edges] - : options?.elements ?? [] + preloadedState.nodes = (storedState.value.nodes ? storedState.value.nodes : options?.nodes ?? []) as GraphNode[] + preloadedState.edges = (storedState.value.edges ? storedState.value.edges : options?.edges ?? []) as GraphEdge[] if (storedState.value.position && storedState.value.zoom) preloadedState.transform = [storedState.value.position[0], storedState.value.position[1], storedState.value.zoom] } diff --git a/src/types/store.ts b/src/types/store.ts index 0e7d228e..b2e2c5c4 100644 --- a/src/types/store.ts +++ b/src/types/store.ts @@ -8,11 +8,10 @@ import { GraphNode, CoordinateExtent, Node } from './node' import { D3Selection, D3Zoom, D3ZoomHandler, KeyCode, PanOnScrollMode } from './zoom' import { FlowHooks, FlowHooksOn } from './hooks' -export interface FlowState extends Omit, 'id'> { +export interface FlowState extends Omit, 'id' | 'elements'> { hooks: FlowHooks instance?: FlowInstance - elements: Elements nodes: GraphNode[] edges: GraphEdge[] @@ -64,7 +63,7 @@ export interface FlowState extends Omit, 'id'> zoomOnDoubleClick: boolean preventScrolling: boolean - isReady: boolean + paneReady: boolean vueFlowVersion: string }