refactor: use injected store so we can use a distinct instance not a global one

This commit is contained in:
Braks
2021-07-13 16:13:15 +02:00
parent 8f727a4d93
commit 6c9d88b09d
13 changed files with 327 additions and 217 deletions
+4 -5
View File
@@ -1,7 +1,6 @@
import { setActivePinia, createPinia, defineStore, StoreDefinition, Pinia } from 'pinia';
import { inject } from 'vue';
import { setActivePinia, createPinia, defineStore, StoreDefinition } from 'pinia';
import isEqual from 'fast-deep-equal';
import { Edge, Node, NodeDiffUpdate, RevueFlowState, RevueFlowActionsTree, XYPosition } from '../types';
import { Edge, Node, NodeDiffUpdate, RevueFlowState, RevueFlowActions, XYPosition } from '../types';
import { getConnectedEdges, getNodesInside, getRectOfNodes, isEdge, isNode, parseEdge, parseNode } from '../utils/graph';
import { clampPosition, getDimensions } from '../utils';
import { getHandleBounds } from '../components/Nodes/utils';
@@ -10,11 +9,11 @@ type NextElements = {
nextNodes: Node[];
nextEdges: Edge[];
};
const pinia = createPinia();
export default function configureStore(
preloadedState: RevueFlowState
): StoreDefinition<any, RevueFlowState, any, RevueFlowActionsTree> {
const pinia = inject<Pinia>(Symbol('pinia')) ?? createPinia();
): StoreDefinition<string, RevueFlowState, any, RevueFlowActions> {
setActivePinia(pinia);
return defineStore({
-1
View File
@@ -58,5 +58,4 @@ export const initialState: RevueFlowState = {
const store = configureStore(initialState);
export type StoreType = typeof store;
export default store;