Skip to content

why use VM? #849

@yylgit

Description

@yylgit

Hi, recently I read the source code of the Vuex. When I read the function of “resetStoreVM”,I see the store._vm is used by the instance of the Vue and the store.state is used the getter to get the “this._vm._data.$$state”.but all the source nowhere use the feature of the VM. absolutely we can use the plain object like this:

get state () {
  return this._state
}

function resetStoreVM (store, state, hot) {
  const oldState = store._state
      store.getters = {}
      const wrappedGetters = store._wrappedGetters
      forEachValue(wrappedGetters, (fn, key) => {
        Object.defineProperty(store.getters, key, {
          get: () => () => fn(store),
          enumerable: true
        })
      })
      store._state = state
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions