diff --git a/docs/md/README.md b/docs/md/README.md index c91ffb3..17602bc 100644 --- a/docs/md/README.md +++ b/docs/md/README.md @@ -766,7 +766,7 @@ const albumRouteMapping = { }), updateState: { id: id => actions.selectAlbum(id), - track: track => actions.playTrack(track) + track: (track, state) => state.id && actions.playTrack(track) } } diff --git a/package.json b/package.json index a483439..91e2052 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ion-router", - "version": "0.11.3", + "version": "0.12.0", "description": "elegant powerful routing based on the simplicity of storing url as state", "main": "lib/index.js", "homepage": "https://cellog.github.io/ion-router", diff --git a/src/helpers.js b/src/helpers.js index cb1e695..0edec37 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -69,7 +69,8 @@ export function getStateUpdates(s, newState) { const oldState = s.state const changes = changed(oldState, newState) const update = s.updateState - return changes.map(key => (update[key] ? update[key](newState[key]) : false)).filter(t => t) + return changes.map(key => (update[key] ? update[key](newState[key], newState) : false)) + .filter(t => t) } export function updateState(s, params, state) { diff --git a/test/helpers.test.js b/test/helpers.test.js index 53d35fd..35d47ee 100644 --- a/test/helpers.test.js +++ b/test/helpers.test.js @@ -159,7 +159,7 @@ describe('helper functions', () => { c: 3, }, updateState: { - a: a => ({ type: 'a', a }), + a: (a, s) => ({ type: 'a', a, b: s.b }), b: b => ({ type: 'b', b }), } }, { @@ -167,7 +167,7 @@ describe('helper functions', () => { b: 2, c: 5, })).eqls([ - { type: 'a', a: 2 }, + { type: 'a', a: 2, b: 2 }, ]) }) it('exitRoute', () => {