Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import applyMixin from './mixin'
import devtoolPlugin from './plugins/devtool'
import ModuleCollection from './module/module-collection'
import { forEachValue, isObject, isPromise, assert } from './util'
import { forEachValue, isObject, isPromise, assert, partial } from './util'

let Vue // bind on install

Expand Down Expand Up @@ -256,7 +256,9 @@ function resetStoreVM (store, state, hot) {
const computed = {}
forEachValue(wrappedGetters, (fn, key) => {
// use computed to leverage its lazy-caching mechanism
computed[key] = () => fn(store)
// direct inline function use will lead to closure preserving oldVm.
// using partial to return function with only arguments preserved in closure enviroment.
computed[key] = partial(fn, store)
Object.defineProperty(store.getters, key, {
get: () => store._vm[key],
enumerable: true // for local getters
Expand Down
6 changes: 6 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ export function isPromise (val) {
export function assert (condition, msg) {
if (!condition) throw new Error(`[vuex] ${msg}`)
}

export function partial (fn, arg) {
return function () {
return fn(arg)
}
}