Map<string, [StoreWithState<string, StateTree>, StateDescriptor<StateTree>]>
>()
-/**
- * A state provider allows to set how states are stored for hydration. e.g. setting a property on a context, getting a property from window
- */
-interface StateProvider {
- (): Record<string, StateTree>
-}
-
-/**
- * Map of initial states used for hydration
- */
-export const stateProviders = new WeakMap<Pinia, StateProvider>()
-
-export function setStateProvider(stateProvider: StateProvider) {
- stateProviders.set(getActivePinia(), stateProvider)
-}
-
-export function getInitialState(id: string): StateTree | undefined {
- const provider = stateProviders.get(getActivePinia())
- return provider && provider()[id]
-}
-
/**
* Gets the root state of all active stores. This is useful when reporting an application crash by
* retrieving the problematic state and send it to your error tracking service.
getActivePinia,
setActivePinia,
storesMap,
- getInitialState,
getClientApp,
piniaSymbol,
Pinia,
| [StoreWithState<Id, S>, StateDescriptor<S>]
| undefined
if (!storeAndDescriptor) {
- storeAndDescriptor = initStore(id, state, getInitialState(id))
+ storeAndDescriptor = initStore(id, state, pinia.state.value[id])
stores.set(id, storeAndDescriptor)