Skip to content

Commit

Permalink
Do not assign if returning undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
nhunzaker committed Sep 21, 2015
1 parent e7b94f6 commit 299a8ca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 9.8.0

### Noticeable changes

- If a store returns undefined, no state change will occur. This is
potentially a breaking change. If you have stores that return
`undefined`, consider changing your logic to support returning `null`

## 9.7.0

- The third argument of store callbacks now contains all application
Expand Down
5 changes: 4 additions & 1 deletion src/Microcosm.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ Microcosm.prototype = {
for (var i = 0; i < this.stores.length; i++) {
var key = this.stores[i][0]
var store = this.stores[i][1]
var answer = send(store, key, state, transaction)

next[key] = send(store, key, state, transaction)
if (answer !== void 0) {
next[key] = answer
}
}

return next
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/serialization-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ describe('Serialization', function() {
assert.equal(false, 'fiz' in app.deserialize(undefined))
})

it ('defaults to getInitialState when no deserialize method is provided', function() {
let app = new Microcosm()

app.addStore('fiz', {
getInitialState() {
return true
}
})

assert.equal(true, app.replace({}).state.fiz)
})

it ('passes the raw data as the seconda argument of deserialize', function(done) {
let app = new Microcosm()

Expand Down

0 comments on commit 299a8ca

Please sign in to comment.