diff --git a/CHANGELOG.md b/CHANGELOG.md index 69bc6b03..49f5f014 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Microcosm.js b/src/Microcosm.js index 3261f61a..222db42a 100644 --- a/src/Microcosm.js +++ b/src/Microcosm.js @@ -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 diff --git a/src/__tests__/serialization-test.js b/src/__tests__/serialization-test.js index 87b8b3b1..4a8ba319 100644 --- a/src/__tests__/serialization-test.js +++ b/src/__tests__/serialization-test.js @@ -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()