Skip to content

Commit

Permalink
fix(store): init _customProperties for devtools (#1704)
Browse files Browse the repository at this point in the history
Co-authored-by: Eduardo San Martin Morote <posva13@gmail.com>
  • Loading branch information
rudyxu1102 and posva committed Oct 8, 2022
1 parent 050ede0 commit 8c1dfce
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions packages/pinia/src/store.ts
Expand Up @@ -47,7 +47,7 @@ import {
_StoreWithState,
} from './types'
import { setActivePinia, piniaSymbol, Pinia, activePinia } from './rootStore'
import { IS_CLIENT } from './env'
import { IS_CLIENT, USE_DEVTOOLS } from './env'
import { patchObject } from './hmr'
import { addSubscription, triggerSubscriptions, noop } from './subscriptions'

Expand Down Expand Up @@ -455,18 +455,17 @@ function createSetupStore<
}

const store: Store<Id, S, G, A> = reactive(
assign(
__DEV__ && IS_CLIENT
? // devtools custom properties
__DEV__ || USE_DEVTOOLS
? assign(
{
_customProperties: markRaw(new Set<string>()),
_hmrPayload,
}
: {},
partialStore
// must be added later
// setupStore
)
_customProperties: markRaw(new Set<string>()), // devtools custom properties
},
partialStore
// must be added later
// setupStore
)
: partialStore
) as unknown as Store<Id, S, G, A>

// store the partial store now so the setup of stores can instantiate each other before they are finished without
Expand Down Expand Up @@ -662,25 +661,25 @@ function createSetupStore<
store._getters = newStore._getters
store._hotUpdating = false
})
}

if (USE_DEVTOOLS) {
const nonEnumerable = {
writable: true,
configurable: true,
// avoid warning on devtools trying to display this property
enumerable: false,
}

if (IS_CLIENT) {
// avoid listing internal properties in devtools
;(
['_p', '_hmrPayload', '_getters', '_customProperties'] as const
).forEach((p) => {
// avoid listing internal properties in devtools
;(['_p', '_hmrPayload', '_getters', '_customProperties'] as const).forEach(
(p) => {
Object.defineProperty(store, p, {
value: store[p],
...nonEnumerable,
})
})
}
}
)
}

/* istanbul ignore if */
Expand All @@ -692,7 +691,7 @@ function createSetupStore<
// apply all plugins
pinia._p.forEach((extender) => {
/* istanbul ignore else */
if (__DEV__ && IS_CLIENT) {
if (USE_DEVTOOLS) {
const extensions = scope.run(() =>
extender({
store,
Expand Down

0 comments on commit 8c1dfce

Please sign in to comment.