)
}
- store = createSetupStore(id, setup, options, pinia, hot)
+ store = createSetupStore(id, setup, options, pinia, hot, true)
store.$reset = function $reset() {
const newState = state ? state() : {}
| DefineSetupStoreOptions<Id, S, G, A>
| DefineStoreOptions<Id, S, G, A> = {},
pinia: Pinia,
- hot?: boolean
+ hot?: boolean,
+ isOptionsStore?: boolean
): Store<Id, S, G, A> {
let scope!: EffectScope
- const buildState = (options as DefineStoreOptions<Id, S, G, A>).state
const optionsForPlugin: DefineStoreOptionsInPlugin<Id, S, G, A> = assign(
{ actions: {} as A },
// avoid setting the state for option stores are it is set
// by the setup
- if (!buildState && !initialState && (!__DEV__ || !hot)) {
+ if (!isOptionsStore && !initialState && (!__DEV__ || !hot)) {
/* istanbul ignore if */
if (isVue2) {
set(pinia.state.value, $id, {})
set(hotState.value, key, toRef(setupStore as any, key))
// createOptionStore directly sets the state in pinia.state.value so we
// can just skip that
- } else if (!buildState) {
+ } else if (!isOptionsStore) {
// in setup stores we must hydrate the state and sync pinia state tree with the refs the user just created
if (initialState && shouldHydrate(prop)) {
if (isRef(prop)) {
} else if (__DEV__) {
// add getters for devtools
if (isComputed(prop)) {
- _hmrPayload.getters[key] = buildState
+ _hmrPayload.getters[key] = isOptionsStore
? // @ts-expect-error
options.getters[key]
: prop
// TODO: does this work in both setup and option store?
for (const getterName in newStore._hmrPayload.getters) {
const getter: _Method = newStore._hmrPayload.getters[getterName]
- const getterValue = buildState
+ const getterValue = isOptionsStore
? // special handling of options api
computed(() => {
setActivePinia(pinia)
// only apply hydrate to option stores with an initial state in pinia
if (
initialState &&
- buildState &&
+ isOptionsStore &&
(options as DefineStoreOptions<Id, S, G, A>).hydrate
) {
;(options as DefineStoreOptions<Id, S, G, A>).hydrate!(
return store
}
-// export function disposeStore(store: StoreGeneric) {
-// store._e
-
-// }
-
/**
* Extract the actions of a store type. Works with both a Setup Store or an
* Options Store.