参数介绍html
new Vuex.Store({...})
生成的对象获取模块的命名空间vue
有命名空间,则以模块名结合"/",造成命名空间路径,即本函数是获取模块的命名空间前缀,如对应下图,moduleC的命名空间前缀为'moduleA/moduleC/',其中moduleB并无设置命名空间vuex
{ moduleA:{ namespaced:true, modules:{ moduleB:{ namespaced:false, modules:{ moduleC:{ namespaced:true, } } } } } }
对于非根模块segmentfault
经过getNestedState,寻找父模块的 state对象。api
调用store的_withCommit函数数组
在_withCommit函数中数据结构
建立模块内容,makeLocalContext(store, namespace, path)。并将生成的content内容放在module.content中。咱们跳转这里,看看makeLocalContext具体操做app
调用module.forEachMutation方法,对模块的mutation方法进行注册ide
registerMutation注册函数函数
调用module.forEachAction方法,对模块的action进行注册
参数介绍
定义local对象
定义local对象的dispatch函数
有命名空间,则在使用 Store 实例的dispatch函数前,对参数进行一些处理
{ moduleA:{ namespaced:true, modules:{ moduleB:{ namespaced:false, modules:{ moduleC:{ namespaced:true, actions: { actionC (context) {...} } } } } } } }
定义commit函数
调用Object.defineProperties函数,往local对象中添加两个变量getters和state,设置local对象的getter和state
定义getters变量,并设置其拦截器。一样的,判断是否有命名空间前缀
不然调用makeLocalGetters函数,生成本身的getters
遍历store.getters中的全部函数,(store.getters变量暂时还未定义到,其指向 store的_wrappedGetters,getter函数容器)
小结,
定义state,及其拦截器
小结