update(store): static id for store state
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -23,7 +23,7 @@ export const createStore = (options?: FlowOptions) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const store = useNewStore(storageKey, preloadedState)
|
const store = useNewStore(storageKey, preloadedState)
|
||||||
if (withStorage && storageKey === store.id?.value) {
|
if (withStorage && storageKey === store.id) {
|
||||||
const toObject = onLoadToObject(store.state)
|
const toObject = onLoadToObject(store.state)
|
||||||
watch(
|
watch(
|
||||||
store.state,
|
store.state,
|
||||||
@@ -39,7 +39,7 @@ export const createStore = (options?: FlowOptions) => {
|
|||||||
export default (options?: FlowOptions): FlowStore => {
|
export default (options?: FlowOptions): FlowStore => {
|
||||||
const currentInstance = getCurrentInstance()
|
const currentInstance = getCurrentInstance()
|
||||||
let store = currentInstance ? inject(StoreSymbol, undefined) : false
|
let store = currentInstance ? inject(StoreSymbol, undefined) : false
|
||||||
if (!store || (store && options?.id && options.id !== store.id?.value)) {
|
if (!store || (store && options?.id && options.id !== store.id)) {
|
||||||
store = createStore(options)
|
store = createStore(options)
|
||||||
}
|
}
|
||||||
if (currentInstance) provide(StoreSymbol, store)
|
if (currentInstance) provide(StoreSymbol, store)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export default (id: string, preloadedState: FlowState): Store => {
|
|||||||
const getters = useGetters(state)
|
const getters = useGetters(state)
|
||||||
const actions = useActions(state, getters)
|
const actions = useActions(state, getters)
|
||||||
return {
|
return {
|
||||||
|
id,
|
||||||
state,
|
state,
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
...getters,
|
...getters,
|
||||||
|
|||||||
+2
-2
@@ -20,7 +20,7 @@ import { NodeExtent, GraphNode, TranslateExtent } from './node'
|
|||||||
import { D3Selection, D3Zoom, D3ZoomHandler, InitD3ZoomPayload } from './zoom'
|
import { D3Selection, D3Zoom, D3ZoomHandler, InitD3ZoomPayload } from './zoom'
|
||||||
import { FlowHooks } from './hooks'
|
import { FlowHooks } from './hooks'
|
||||||
|
|
||||||
export interface FlowState extends Omit<FlowOptions, 'elements'> {
|
export interface FlowState extends Omit<FlowOptions, 'elements' | 'id'> {
|
||||||
hooks: FlowHooks
|
hooks: FlowHooks
|
||||||
instance?: FlowInstance
|
instance?: FlowInstance
|
||||||
|
|
||||||
@@ -89,5 +89,5 @@ export interface FlowGetters {
|
|||||||
getSelectedNodes: ComputedRef<GraphNode[]>
|
getSelectedNodes: ComputedRef<GraphNode[]>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Store = { state: FlowState } & ToRefs<FlowState> & FlowActions & FlowGetters
|
export type Store = { id: string; state: FlowState } & ToRefs<FlowState> & FlowActions & FlowGetters
|
||||||
export type FlowStore = UnwrapNestedRefs<Store>
|
export type FlowStore = UnwrapNestedRefs<Store>
|
||||||
|
|||||||
Reference in New Issue
Block a user