Skip to content

Commit 0006765

Browse files
jnxeykiaking
andauthored
fix: fix getters getting re-evaluated on every access (#1823) (#1860)
Co-authored-by: Kia Ishii <[email protected]>
1 parent 4ace559 commit 0006765

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/store.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,15 @@ function resetStoreState (store, state, hot) {
286286
store._makeLocalGettersCache = Object.create(null)
287287
const wrappedGetters = store._wrappedGetters
288288
const computedObj = {}
289+
const computedCache = {}
289290
forEachValue(wrappedGetters, (fn, key) => {
290291
// use computed to leverage its lazy-caching mechanism
291292
// direct inline function use will lead to closure preserving oldVm.
292293
// using partial to return function with only arguments preserved in closure environment.
293294
computedObj[key] = partial(fn, store)
295+
computedCache[key] = computed(() => computedObj[key]())
294296
Object.defineProperty(store.getters, key, {
295-
get: () => computed(() => computedObj[key]()).value,
297+
get: () => computedCache[key].value,
296298
enumerable: true // for local getters
297299
})
298300
})

0 commit comments

Comments
 (0)