瀏覽代碼

test dynamic module registration (fix #243)

Evan You 8 年之前
父節點
當前提交
17d80ffd07
共有 2 個文件被更改,包括 17 次插入0 次删除
  1. 2 0
      src/index.js
  2. 15 0
      test/unit/test.js

+ 2 - 0
src/index.js

@@ -63,6 +63,7 @@ class Store {
   }
 
   module (path, module, hot) {
+    this._committing = true
     if (typeof path === 'string') path = [path]
     assert(Array.isArray(path), `module path must be a string or an Array.`)
 
@@ -99,6 +100,7 @@ class Store {
         this.module(path.concat(key), modules[key], hot)
       })
     }
+    this._committing = false
   }
 
   mutation (type, handler, path = []) {

+ 15 - 0
test/unit/test.js

@@ -191,6 +191,21 @@ describe('Vuex', () => {
     expect(store.getters.hasAny).to.equal(true)
   })
 
+  it('dynamic module registration', () => {
+    const store = new Vuex.Store({
+      strict: true
+    })
+    expect(() => {
+      store.module('hi', {
+        state: { a: 1 },
+        mutations: { inc: state => state.a++ }
+      })
+    }).not.to.throw()
+    expect(store.state.hi.a).to.equal(1)
+    store.commit('inc')
+    expect(store.state.hi.a).to.equal(2)
+  })
+
   it('store injection', () => {
     const store = new Vuex.Store()
     const vm = new Vue({