Explorar o código

add replace state method

Evan You %!s(int64=9) %!d(string=hai) anos
pai
achega
3fff85fdfe
Modificáronse 1 ficheiros con 12 adicións e 0 borrados
  1. 12 0
      src/index.js

+ 12 - 0
src/index.js

@@ -129,6 +129,18 @@ export class Store {
     this._setupModuleMutations(modules || this._modules)
   }
 
+  /**
+   * Replace entire state tree.
+   */
+
+  replaceState (newState) {
+    const state = this._vm._data
+    const clone = deepClone(newState)
+    Object.keys(clone).forEach(key => {
+      state[key] = clone[key]
+    })
+  }
+
   /**
    * Attach sub state tree of each module to the root tree.
    *