@@ -163,7 +163,7 @@ function createOptionsStore<
163
163
)
164
164
}
165
165
166
- store = createSetupStore ( id , setup , options , pinia , hot )
166
+ store = createSetupStore ( id , setup , options , pinia , hot , true )
167
167
168
168
store . $reset = function $reset ( ) {
169
169
const newState = state ? state ( ) : { }
@@ -189,10 +189,10 @@ function createSetupStore<
189
189
| DefineSetupStoreOptions < Id , S , G , A >
190
190
| DefineStoreOptions < Id , S , G , A > = { } ,
191
191
pinia : Pinia ,
192
- hot ?: boolean
192
+ hot ?: boolean ,
193
+ isOptionsStore ?: boolean
193
194
) : Store < Id , S , G , A > {
194
195
let scope ! : EffectScope
195
- const buildState = ( options as DefineStoreOptions < Id , S , G , A > ) . state
196
196
197
197
const optionsForPlugin : DefineStoreOptionsInPlugin < Id , S , G , A > = assign (
198
198
{ actions : { } as A } ,
@@ -241,7 +241,7 @@ function createSetupStore<
241
241
242
242
// avoid setting the state for option stores are it is set
243
243
// by the setup
244
- if ( ! buildState && ! initialState && ( ! __DEV__ || ! hot ) ) {
244
+ if ( ! isOptionsStore && ! initialState && ( ! __DEV__ || ! hot ) ) {
245
245
/* istanbul ignore if */
246
246
if ( isVue2 ) {
247
247
set ( pinia . state . value , $id , { } )
@@ -459,7 +459,7 @@ function createSetupStore<
459
459
set ( hotState . value , key , toRef ( setupStore as any , key ) )
460
460
// createOptionStore directly sets the state in pinia.state.value so we
461
461
// can just skip that
462
- } else if ( ! buildState ) {
462
+ } else if ( ! isOptionsStore ) {
463
463
// in setup stores we must hydrate the state and sync pinia state tree with the refs the user just created
464
464
if ( initialState && shouldHydrate ( prop ) ) {
465
465
if ( isRef ( prop ) ) {
@@ -507,7 +507,7 @@ function createSetupStore<
507
507
} else if ( __DEV__ ) {
508
508
// add getters for devtools
509
509
if ( isComputed ( prop ) ) {
510
- _hmrPayload . getters [ key ] = buildState
510
+ _hmrPayload . getters [ key ] = isOptionsStore
511
511
? // @ts -expect-error
512
512
options . getters [ key ]
513
513
: prop
@@ -605,7 +605,7 @@ function createSetupStore<
605
605
// TODO: does this work in both setup and option store?
606
606
for ( const getterName in newStore . _hmrPayload . getters ) {
607
607
const getter : _Method = newStore . _hmrPayload . getters [ getterName ]
608
- const getterValue = buildState
608
+ const getterValue = isOptionsStore
609
609
? // special handling of options api
610
610
computed ( ( ) => {
611
611
setActivePinia ( pinia )
@@ -710,7 +710,7 @@ function createSetupStore<
710
710
// only apply hydrate to option stores with an initial state in pinia
711
711
if (
712
712
initialState &&
713
- buildState &&
713
+ isOptionsStore &&
714
714
( options as DefineStoreOptions < Id , S , G , A > ) . hydrate
715
715
) {
716
716
; ( options as DefineStoreOptions < Id , S , G , A > ) . hydrate ! (
@@ -724,11 +724,6 @@ function createSetupStore<
724
724
return store
725
725
}
726
726
727
- // export function disposeStore(store: StoreGeneric) {
728
- // store._e
729
-
730
- // }
731
-
732
727
/**
733
728
* Extract the actions of a store type. Works with both a Setup Store or an
734
729
* Options Store.
0 commit comments