Evan You před 9 roky
rodič
revize
e54cf294d2
2 změnil soubory, kde provedl 4 přidání a 13 odebrání
  1. 2 4
      examples/todomvc/vuex/middlewares.js
  2. 2 9
      src/index.js

+ 2 - 4
examples/todomvc/vuex/middlewares.js

@@ -1,7 +1,5 @@
 import { STORAGE_KEY } from './index'
 
-export default [{
-  after: function (mutation, { todos }) {
-    localStorage.setItem(STORAGE_KEY, JSON.stringify(todos))
-  }
+export default [function (mutation, { todos }) {
+  localStorage.setItem(STORAGE_KEY, JSON.stringify(todos))
 }]

+ 2 - 9
src/index.js

@@ -17,12 +17,9 @@ export default class Vuex {
     state = {},
     actions = {},
     mutations = {},
-    middlewares = [],
-    debug = false
+    middlewares = []
   } = {}) {
 
-    this._debug = debug
-
     // use a Vue instance to store the state tree
     this._vm = new Vue({
       data: state
@@ -69,10 +66,6 @@ export default class Vuex {
     const mutation = this._mutations[type]
     const state = this.state
     if (mutation) {
-      // middleware before hooks
-      this._middlewares.forEach(middleware => {
-        middleware.before && middleware.before({ type, payload }, state)
-      })
       if (Array.isArray(mutation)) {
         mutation.forEach(m => m(state, ...payload))
       } else {
@@ -80,7 +73,7 @@ export default class Vuex {
       }
       // middleware after hooks
       this._middlewares.forEach(middleware => {
-        middleware.after && middleware.after({ type, payload }, state)
+        middleware({ type, payload }, state)
       })
     } else {
       console.warn(`[vuex] Unknown mutation: ${ type }`)