From: Eduardo San Martin Morote Date: Tue, 5 Jan 2021 14:54:04 +0000 (+0100) Subject: refactor: remove setStateProvider() X-Git-Tag: v2.0.0-alpha.7~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=502a32832cfdb1a27a033ba2b7be578b090697de;p=thirdparty%2Fvuejs%2Fpinia.git 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. --- 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)