|
@@ -67,14 +67,20 @@ export default class Vuex {
|
|
|
|
|
|
dispatch (type, ...payload) {
|
|
dispatch (type, ...payload) {
|
|
const mutation = this._mutations[type]
|
|
const mutation = this._mutations[type]
|
|
|
|
+ const state = this.state
|
|
if (mutation) {
|
|
if (mutation) {
|
|
|
|
+ // middleware before hooks
|
|
|
|
+ this._middlewares.forEach(middleware => {
|
|
|
|
+ middleware.before && middleware.before({ type, payload }, state)
|
|
|
|
+ })
|
|
if (Array.isArray(mutation)) {
|
|
if (Array.isArray(mutation)) {
|
|
- mutation.forEach(m => m(this.state, ...payload))
|
|
|
|
|
|
+ mutation.forEach(m => m(state, ...payload))
|
|
} else {
|
|
} else {
|
|
- mutation(this.state, ...payload)
|
|
|
|
|
|
+ mutation(state, ...payload)
|
|
}
|
|
}
|
|
|
|
+ // middleware after hooks
|
|
this._middlewares.forEach(middleware => {
|
|
this._middlewares.forEach(middleware => {
|
|
- middleware({ type, payload }, this.state)
|
|
|
|
|
|
+ middleware.after && middleware.after({ type, payload }, state)
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
console.warn(`[vuex] Unknown mutation: ${ type }`)
|
|
console.warn(`[vuex] Unknown mutation: ${ type }`)
|