Browse Source

fix: fix getters getting re-evaluated on every access (#1823) (#1860)

Co-authored-by: Kia Ishii <kia.king.08@gmail.com>
jnxey 4 years ago
parent
commit
0006765ca3
1 changed files with 3 additions and 1 deletions
  1. 3 1
      src/store.js

+ 3 - 1
src/store.js

@@ -286,13 +286,15 @@ function resetStoreState (store, state, hot) {
   store._makeLocalGettersCache = Object.create(null)
   const wrappedGetters = store._wrappedGetters
   const computedObj = {}
+  const computedCache = {}
   forEachValue(wrappedGetters, (fn, key) => {
     // use computed to leverage its lazy-caching mechanism
     // direct inline function use will lead to closure preserving oldVm.
     // using partial to return function with only arguments preserved in closure environment.
     computedObj[key] = partial(fn, store)
+    computedCache[key] = computed(() => computedObj[key]())
     Object.defineProperty(store.getters, key, {
-      get: () => computed(() => computedObj[key]()).value,
+      get: () => computedCache[key].value,
       enumerable: true // for local getters
     })
   })