From 502a32832cfdb1a27a033ba2b7be578b090697de Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 5 Jan 2021 15:54:04 +0100 Subject: [PATCH] refactor: remove setStateProvider() BREAKING_CHANGE: `setStateProvider()` has been removed as you you can directly set `pinia.state.value` instead. This affects SSR implementations in particular. --- src/index.ts | 1 - src/rootStore.ts | 21 --------------------- src/store.ts | 3 +-- 3 files changed, 1 insertion(+), 24 deletions(-) diff --git a/src/index.ts b/src/index.ts index dfabe420..31b5c488 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,5 @@ export { setActivePinia, - setStateProvider, getRootState, createPinia, Pinia, diff --git a/src/rootStore.ts b/src/rootStore.ts index 9aabaa4a..93b3ddc2 100644 --- a/src/rootStore.ts +++ b/src/rootStore.ts @@ -49,27 +49,6 @@ export const storesMap = new WeakMap< Map, StateDescriptor]> >() -/** - * 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 -} - -/** - * Map of initial states used for hydration - */ -export const stateProviders = new WeakMap() - -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. diff --git a/src/store.ts b/src/store.ts index bc08d836..9047d028 100644 --- a/src/store.ts +++ b/src/store.ts @@ -15,7 +15,6 @@ import { getActivePinia, setActivePinia, storesMap, - getInitialState, getClientApp, piniaSymbol, Pinia, @@ -265,7 +264,7 @@ export function defineStore< | [StoreWithState, StateDescriptor] | undefined if (!storeAndDescriptor) { - storeAndDescriptor = initStore(id, state, getInitialState(id)) + storeAndDescriptor = initStore(id, state, pinia.state.value[id]) stores.set(id, storeAndDescriptor) -- 2.47.3