1
1
import applyMixin from './mixin'
2
2
import devtoolPlugin from './plugins/devtool'
3
3
import ModuleCollection from './module/module-collection'
4
- import { forEachValue , isObject , isPromise , assert } from './util'
4
+ import { compose , forEachValue , isObject , isPromise , assert } from './util'
5
5
6
6
let Vue // bind on install
7
7
@@ -21,6 +21,7 @@ export class Store {
21
21
}
22
22
23
23
const {
24
+ actionEnhancers = [ ] ,
24
25
plugins = [ ] ,
25
26
strict = false
26
27
} = options
@@ -42,9 +43,14 @@ export class Store {
42
43
this . _subscribers = [ ]
43
44
this . _watcherVM = new Vue ( )
44
45
45
- // bind commit and dispatch to self
46
46
const store = this
47
- const { dispatch, commit } = this
47
+ const { commit } = this
48
+ let { dispatch } = this
49
+
50
+ const actionEnhancerChain = getActionEnhancerChain ( store , state , actionEnhancers )
51
+ dispatch = compose ( ...actionEnhancerChain ) ( dispatch . bind ( store ) )
52
+
53
+ // bind commit and dispatch to self
48
54
this . dispatch = function boundDispatch ( type , payload ) {
49
55
return dispatch . call ( store , type , payload )
50
56
}
@@ -438,6 +444,15 @@ function enableStrictMode (store) {
438
444
} , { deep : true , sync : true } )
439
445
}
440
446
447
+ function getActionEnhancerChain ( store , state , actionEnhancers ) {
448
+ return actionEnhancers . map ( actionEnhancer => actionEnhancer ( {
449
+ dispatch : store . dispatch ,
450
+ commit : store . commit ,
451
+ getters : store . getters ,
452
+ state
453
+ } ) )
454
+ }
455
+
441
456
function getNestedState ( state , path ) {
442
457
return path . length
443
458
? path . reduce ( ( state , key ) => state [ key ] , state )
0 commit comments