Skip to content

Commit bc61bf6

Browse files
committed
module option change: namespace: string -> namespaced: boolean
1 parent 1b81363 commit bc61bf6

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

src/module/module-collection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class ModuleCollection {
2424
let module = this.root
2525
return path.reduce((namespace, key) => {
2626
module = module.getChild(key)
27-
return namespace + module.namespace
27+
return namespace + (module.namespaced ? key + '/' : '')
2828
}, '')
2929
}
3030

src/module/module.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export default class Module {
1111
return this._rawModule.state || {}
1212
}
1313

14-
get namespace () {
15-
return this._rawModule.namespace || ''
14+
get namespaced () {
15+
return !!this._rawModule.namespaced
1616
}
1717

1818
addChild (key, module) {
@@ -28,7 +28,7 @@ export default class Module {
2828
}
2929

3030
update (rawModule) {
31-
this._rawModule.namespace = rawModule.namespace
31+
this._rawModule.namespaced = rawModule.namespaced
3232
if (rawModule.actions) {
3333
this._rawModule.actions = rawModule.actions
3434
}

test/unit/module/module-collection.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ describe('ModuleCollection', () => {
2525
})
2626

2727
it('getNamespace', () => {
28-
const module = (namespace, children) => {
28+
const module = (namespaced, children) => {
2929
return {
30-
namespace,
30+
namespaced,
3131
modules: children
3232
}
3333
}
3434
const collection = new ModuleCollection({
3535
namespace: 'ignore/', // root module namespace should be ignored
3636
modules: {
37-
a: module('a/', {
38-
b: module(null, {
39-
c: module('c/')
37+
a: module(true, {
38+
b: module(false, {
39+
c: module(true)
4040
}),
41-
d: module('d/')
41+
d: module(true)
4242
})
4343
}
4444
})

test/unit/module/module.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ describe('Module', () => {
1717

1818
it('get namespacer: no namespace option', () => {
1919
const module = new Module({})
20-
expect(module.namespace).toBe('')
20+
expect(module.namespaced).toBe(false)
2121
})
2222

23-
it('get namespacer: namespace option is string value', () => {
23+
it('get namespacer: namespace option is true', () => {
2424
const module = new Module({
25-
namespace: 'prefix/'
25+
namespaced: true
2626
})
27-
expect(module.namespace).toBe('prefix/')
27+
expect(module.namespaced).toBe(true)
2828
})
2929
})

test/unit/test.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ describe('Vuex', () => {
251251
const store = new Vuex.Store({
252252
modules: {
253253
a: {
254-
namespace: 'prefix/'
254+
namespaced: true
255255
}
256256
}
257257
})
@@ -265,12 +265,12 @@ describe('Vuex', () => {
265265
})
266266

267267
expect(store.state.a.b.value).toBe(1)
268-
expect(store.getters['prefix/foo']).toBe(1)
268+
expect(store.getters['a/foo']).toBe(1)
269269

270-
store.dispatch('prefix/foo')
270+
store.dispatch('a/foo')
271271
expect(actionSpy).toHaveBeenCalled()
272272

273-
store.commit('prefix/foo')
273+
store.commit('a/foo')
274274
expect(mutationSpy).toHaveBeenCalled()
275275
})
276276

@@ -614,7 +614,7 @@ describe('Vuex', () => {
614614
const store = new Vuex.Store({
615615
modules: {
616616
a: {
617-
namespace: 'prefix/',
617+
namespaced: true,
618618
state: {
619619
a: 1
620620
},
@@ -632,26 +632,26 @@ describe('Vuex', () => {
632632
})
633633

634634
expect(store.state.a.a).toBe(1)
635-
expect(store.getters['prefix/b']).toBe(2)
636-
store.dispatch('prefix/' + TEST)
635+
expect(store.getters['a/b']).toBe(2)
636+
store.dispatch('a/' + TEST)
637637
expect(actionSpy).toHaveBeenCalled()
638-
store.commit('prefix/' + TEST)
638+
store.commit('a/' + TEST)
639639
expect(mutationSpy).toHaveBeenCalled()
640640
})
641641

642642
it('module: nested namespace', () => {
643643
// mock module generator
644644
const actionSpys = []
645645
const mutationSpys = []
646-
const createModule = (name, namespace, children) => {
646+
const createModule = (name, namespaced, children) => {
647647
const actionSpy = jasmine.createSpy()
648648
const mutationSpy = jasmine.createSpy()
649649

650650
actionSpys.push(actionSpy)
651651
mutationSpys.push(mutationSpy)
652652

653653
return {
654-
namespace,
654+
namespaced,
655655
state: {
656656
[name]: true
657657
},
@@ -670,11 +670,11 @@ describe('Vuex', () => {
670670

671671
// mock module
672672
const modules = {
673-
a: createModule('a', 'a/', { // a/a
674-
b: createModule('b', null, { // a/b - does not add namespace
675-
c: createModule('c', 'c/') // a/c/c
673+
a: createModule('a', true, { // a/a
674+
b: createModule('b', false, { // a/b - does not add namespace
675+
c: createModule('c', true) // a/c/c
676676
}),
677-
d: createModule('d', 'd/'), // a/d/d
677+
d: createModule('d', true), // a/d/d
678678
})
679679
}
680680

@@ -714,7 +714,7 @@ describe('Vuex', () => {
714714
},
715715
modules: {
716716
a: {
717-
namespace: 'prefix/',
717+
namespaced: true,
718718
state: { value: 'module' },
719719
getters: {
720720
foo: state => state.value,
@@ -725,9 +725,9 @@ describe('Vuex', () => {
725725
}
726726
})
727727

728-
expect(store.getters['prefix/foo']).toBe('module')
729-
expect(store.getters['prefix/bar']).toBe('module')
730-
expect(store.getters['prefix/baz']).toBe('root')
728+
expect(store.getters['a/foo']).toBe('module')
729+
expect(store.getters['a/bar']).toBe('module')
730+
expect(store.getters['a/baz']).toBe('root')
731731
})
732732

733733
it('module: action context is namespaced in namespaced module', done => {
@@ -743,7 +743,7 @@ describe('Vuex', () => {
743743
mutations: { foo: rootMutationSpy },
744744
modules: {
745745
a: {
746-
namespace: 'prefix/',
746+
namespaced: true,
747747
state: { value: 'module' },
748748
getters: { foo: state => state.value },
749749
actions: {
@@ -770,7 +770,7 @@ describe('Vuex', () => {
770770
}
771771
})
772772

773-
store.dispatch('prefix/test')
773+
store.dispatch('a/test')
774774
})
775775

776776
it('module: use other module that has same namespace', done => {
@@ -780,7 +780,7 @@ describe('Vuex', () => {
780780
const store = new Vuex.Store({
781781
modules: {
782782
parent: {
783-
namespace: 'prefix/',
783+
namespaced: true,
784784

785785
modules: {
786786
a: {
@@ -813,7 +813,7 @@ describe('Vuex', () => {
813813
}
814814
})
815815

816-
store.dispatch('prefix/test')
816+
store.dispatch('parent/test')
817817
})
818818

819819
it('dispatching multiple actions in different modules', done => {
@@ -1210,7 +1210,7 @@ describe('Vuex', () => {
12101210
const store = new Vuex.Store({
12111211
modules: {
12121212
a: {
1213-
namespace: 'prefix/',
1213+
namespaced: true,
12141214
state: { value: 1 },
12151215
getters: { foo: state => state.value },
12161216
actions: { foo: actionSpy },
@@ -1220,38 +1220,38 @@ describe('Vuex', () => {
12201220
})
12211221

12221222
expect(store.state.a.value).toBe(1)
1223-
expect(store.getters['prefix/foo']).toBe(1)
1224-
store.dispatch('prefix/foo')
1223+
expect(store.getters['a/foo']).toBe(1)
1224+
store.dispatch('a/foo')
12251225
expect(actionSpy.calls.count()).toBe(1)
1226-
store.commit('prefix/foo')
1226+
store.commit('a/foo')
12271227
expect(actionSpy.calls.count()).toBe(1)
12281228

12291229
store.hotUpdate({
12301230
modules: {
12311231
a: {
1232-
namespace: 'prefix-changed/'
1232+
namespaced: false
12331233
}
12341234
}
12351235
})
12361236

12371237
expect(store.state.a.value).toBe(1)
1238-
expect(store.getters['prefix/foo']).toBe(undefined) // removed
1239-
expect(store.getters['prefix-changed/foo']).toBe(1) // renamed
1238+
expect(store.getters['a/foo']).toBe(undefined) // removed
1239+
expect(store.getters['foo']).toBe(1) // renamed
12401240

12411241
// should not be called
1242-
store.dispatch('prefix/foo')
1242+
store.dispatch('a/foo')
12431243
expect(actionSpy.calls.count()).toBe(1)
12441244

12451245
// should be called
1246-
store.dispatch('prefix-changed/foo')
1246+
store.dispatch('foo')
12471247
expect(actionSpy.calls.count()).toBe(2)
12481248

12491249
// should not be called
1250-
store.commit('prefix/foo')
1250+
store.commit('a/foo')
12511251
expect(mutationSpy.calls.count()).toBe(1)
12521252

12531253
// should be called
1254-
store.commit('prefix-changed/foo')
1254+
store.commit('foo')
12551255
expect(mutationSpy.calls.count()).toBe(2)
12561256
})
12571257

0 commit comments

Comments
 (0)