Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue#1507 : Memory leak happening while using registerModule/u… #1508

Merged
merged 3 commits into from
Mar 25, 2019
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)
parth67 marked this conversation as resolved.
Show resolved Hide resolved
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)
}
}