Skip to content

Commit

Permalink
Merge pull request #54 from mantoni/master
Browse files Browse the repository at this point in the history
model: initialize namespaced state with empty object
  • Loading branch information
yoshuawuyts committed Jul 18, 2016
2 parents c5ca316 + 30488d7 commit 2ce1d40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ function dispatcher (handlers) {
// which is used to nest properties.
// (str, obj, obj, fn?) -> null
function apply (ns, source, target, createSend, done) {
if (ns && !target[ns]) target[ns] = {}
Object.keys(source).forEach(function (key) {
if (ns) {
if (!target[ns]) target[ns] = {}
target[ns][key] = source[key]
} else {
target[key] = source[key]
Expand Down
15 changes: 15 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ tape('api: state = store.state()', (t) => {
t.deepEqual(state, { foo: 'bar' })
})

t.test('should initialize state with empty namespace object', (t) => {
t.plan(1)
const store = barracks()
store.model({
namespace: 'beep',
state: {}
})
store.start()
const state = store.state()
const expected = {
beep: {}
}
t.deepEqual(expected, state, 'has initial empty namespace object')
})

t.test('should return the combined state', (t) => {
t.plan(1)
const store = barracks()
Expand Down

0 comments on commit 2ce1d40

Please sign in to comment.