Explorar o código

refactor: rename `vm` to `state` since in vue 3 we don't use vm anymore

Kia Ishii %!s(int64=5) %!d(string=hai) anos
pai
achega
4f183aabe7
Modificáronse 1 ficheiros con 16 adicións e 18 borrados
  1. 16 18
      src/store.js

+ 16 - 18
src/store.js

@@ -51,9 +51,9 @@ export class Store {
     // and collects all module getters inside this._wrappedGetters
     installModule(this, state, [], this._modules.root)
 
-    // initialize the store vm, which is responsible for the reactivity
+    // initialize the store state, which is responsible for the reactivity
     // (also registers _wrappedGetters as computed properties)
-    resetStoreVM(this, state)
+    resetStoreState(this, state)
 
     // apply plugins
     plugins.forEach(plugin => plugin(this))
@@ -69,7 +69,7 @@ export class Store {
   }
 
   get state () {
-    return this._vm._data.$$state
+    return this._state.data
   }
 
   set state (v) {
@@ -180,7 +180,7 @@ export class Store {
 
   replaceState (state) {
     this._withCommit(() => {
-      this._vm._data.$$state = state
+      this._state.data = state
     })
   }
 
@@ -195,7 +195,7 @@ export class Store {
     this._modules.register(path, rawModule)
     installModule(this, this.state, path, this._modules.get(path), options.preserveState)
     // reset store to update getters...
-    resetStoreVM(this, this.state)
+    resetStoreState(this, this.state)
   }
 
   unregisterModule (path) {
@@ -246,12 +246,12 @@ function resetStore (store, hot) {
   const state = store.state
   // init all modules
   installModule(store, state, [], store._modules.root, true)
-  // reset vm
-  resetStoreVM(store, state, hot)
+  // reset state
+  resetStoreState(store, state, hot)
 }
 
-function resetStoreVM (store, state, hot) {
-  const oldVm = store._vm
+function resetStoreState (store, state, hot) {
+  const oldState = store._state
 
   // bind store public getters
   store.getters = {}
@@ -277,23 +277,21 @@ function resetStoreVM (store, state, hot) {
   //
   // New impl with reactive. Defining redundunt keys to make it as close as
   // the old impl api.
-  store._vm = reactive({
-    _data: {
-      $$state: state
-    }
+  store._state = reactive({
+    data: state
   })
 
-  // enable strict mode for new vm
+  // enable strict mode for new state
   if (store.strict) {
     enableStrictMode(store)
   }
 
-  if (oldVm) {
+  if (oldState) {
     if (hot) {
       // dispatch changes in all subscribed watchers
       // to force getter re-evaluation for hot reloading.
       store._withCommit(() => {
-        oldVm._data.$$state = null
+        oldState.data = null
       })
     }
     // TODO: I think we don't need this anymore since we're not using vm?
@@ -394,7 +392,7 @@ function makeLocalContext (store, namespace, path) {
   }
 
   // getters and state object must be gotten lazily
-  // because they will be changed by vm update
+  // because they will be changed by state update
   Object.defineProperties(local, {
     getters: {
       get: noNamespace
@@ -484,7 +482,7 @@ function registerGetter (store, type, rawGetter, local) {
 }
 
 function enableStrictMode (store) {
-  watch(() => store._vm._data.$$state, () => {
+  watch(() => store._state.data, () => {
     if (process.env.NODE_ENV !== 'production') {
       assert(store._committing, `do not mutate vuex store state outside mutation handlers.`)
     }