@@ -35,12 +35,12 @@ export class Store {
35
35
// store internal state
36
36
this . _committing = false
37
37
this . _actions = Object . create ( null ) // 存放 actions
38
- this . _actionSubscribers = [ ] // actions 订阅者
38
+ this . _actionSubscribers = [ ] // action 订阅者
39
39
this . _mutations = Object . create ( null ) // 存放 mutations
40
40
this . _wrappedGetters = Object . create ( null ) // 存放 getters
41
41
this . _modules = new ModuleCollection ( options ) // module 收集器
42
42
this . _modulesNamespaceMap = Object . create ( null )
43
- this . _subscribers = [ ] // 订阅者
43
+ this . _subscribers = [ ] // mutation 订阅者
44
44
this . _watcherVM = new Vue ( )
45
45
this . _makeLocalGettersCache = Object . create ( null ) // namespaced module 对应 getters 代理的缓存
46
46
@@ -123,9 +123,10 @@ export class Store {
123
123
} )
124
124
} )
125
125
126
+ // 通知所有 mutation 订阅者
126
127
this . _subscribers
127
128
. slice ( ) // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe
128
- . forEach ( sub => sub ( mutation , this . state ) )
129
+ . forEach ( sub => sub ( mutation , this . state /* 最新的 state */ ) )
129
130
130
131
if (
131
132
__DEV__ &&
@@ -157,6 +158,7 @@ export class Store {
157
158
}
158
159
159
160
try {
161
+ // 通知所有 action 订阅者
160
162
this . _actionSubscribers
161
163
. slice ( ) // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe
162
164
. filter ( sub => sub . before )
@@ -204,6 +206,7 @@ export class Store {
204
206
} )
205
207
}
206
208
209
+ // 注册一个订阅函数,返回一个取消订阅的函数
207
210
subscribe ( fn , options ) {
208
211
return genericSubscribe ( fn , this . _subscribers , options )
209
212
}
@@ -289,6 +292,7 @@ export class Store {
289
292
}
290
293
}
291
294
295
+ // 注册一个订阅函数,返回一个取消订阅的函数
292
296
function genericSubscribe ( fn , subs , options ) {
293
297
if ( subs . indexOf ( fn ) < 0 ) {
294
298
options && options . prepend
0 commit comments