From 96d54c59dc2872e651ed5d8f7fee8e93c21afacf Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Wed, 24 Nov 2021 16:43:24 +0100 Subject: [PATCH] refactor(store): check if state variables have to be re-set * instead of just pasting over the state constantly check what needs to be re-set Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com> --- src/container/VueFlow/VueFlow.vue | 39 +++++++------ src/store/stateStore.ts | 87 ++++++++++++++++++--------- src/types/flow.ts | 5 ++ src/types/store.ts | 3 +- src/utils/graph.ts | 97 ++++++++++++++++++++----------- 5 files changed, 150 insertions(+), 81 deletions(-) diff --git a/src/container/VueFlow/VueFlow.vue b/src/container/VueFlow/VueFlow.vue index 3cad1375..ad20f503 100644 --- a/src/container/VueFlow/VueFlow.vue +++ b/src/container/VueFlow/VueFlow.vue @@ -11,7 +11,6 @@ import { NodeExtent, NodeTypes, EdgeTypes, - FlowState, FlowInstance, Loading, FlowOptions, @@ -116,7 +115,7 @@ const options = Object.assign({}, store.$state, props) invoke(async () => { store.setState(options) - store.setElements(elements.value) + await store.setElements(elements.value) store.isReady = true // if ssr we can't wait for dimensions, they'll never really exist @@ -139,26 +138,25 @@ invoke(async () => { store.instance = instance watch( () => props, - () => store.setState({ ...store.$state, ...props } as FlowState), + () => store.setState(props), + { flush: 'post', deep: true }, + ) + watch( + () => props.modelValue.length, + () => store.setElements(elements.value), + ) + const { pause, resume } = pausableWatch(elements, store.setElements, { flush: 'post' }) + watch( + () => store.elements, + (val) => { + pause() + elements.value = val + nextTick(resume) + }, { flush: 'post', deep: true }, ) }) -watch( - () => props.modelValue.length, - () => store.setElements(elements.value), -) -const { pause, resume } = pausableWatch(elements, store.setElements, { flush: 'post' }) -watch( - () => store.elements, - (val) => { - pause() - elements.value = val - nextTick(resume) - }, - { flush: 'post', deep: true }, -) - const transitionName = computed(() => { let name = '' if (typeof store.loading === 'object' && store.loading.transition) { @@ -170,6 +168,11 @@ const transitionName = computed(() => { onBeforeUnmount(() => store?.$dispose()) +