From a1d778e00cf1829bc4dfc7f7b16dfa65c5e2c5f4 Mon Sep 17 00:00:00 2001 From: Kim Joar Bekkelund Date: Wed, 9 Dec 2015 10:52:49 +0100 Subject: [PATCH 1/2] Remove INIT_PATH --- src/index.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/index.js b/src/index.js index a2e007c..cd39b78 100644 --- a/src/index.js +++ b/src/index.js @@ -2,24 +2,9 @@ import deepEqual from 'deep-equal' // Constants -const INIT_PATH = '@@router/INIT_PATH' export const UPDATE_PATH = '@@router/UPDATE_PATH' const SELECT_STATE = state => state.routing -// Action creators - -function initPath(path, state) { - return { - type: INIT_PATH, - payload: { - path: path, - state: state, - replace: false, - avoidRouterUpdate: true - } - } -} - export function pushPath(path, state, { avoidRouterUpdate = false } = {}) { return { type: UPDATE_PATH, @@ -54,7 +39,7 @@ let initialState = { } function update(state=initialState, { type, payload }) { - if(type === INIT_PATH || type === UPDATE_PATH) { + if(type === UPDATE_PATH) { return Object.assign({}, state, { path: payload.path, changeId: state.changeId + (payload.avoidRouterUpdate ? 0 : 1), @@ -128,7 +113,8 @@ export function syncReduxAndRouter(history, store, selectRouterState = SELECT_ST // trigger an unnecessary `pushState` on load lastRoute = initialState - store.dispatch(initPath(route.path, route.state)) + const method = location.action === 'REPLACE' ? replacePath : pushPath; + store.dispatch(method(route.path, route.state, { avoidRouterUpdate: true })); } else if(!locationsAreEqual(getRouterState(), route)) { // The above check avoids dispatching an action if the store is // already up-to-date From a985b5b810d674021920e8039f182d2d35302764 Mon Sep 17 00:00:00 2001 From: Kim Joar Bekkelund Date: Thu, 10 Dec 2015 09:54:40 +0100 Subject: [PATCH 2/2] Always push path on initial route --- src/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index cd39b78..3f4d4b6 100644 --- a/src/index.js +++ b/src/index.js @@ -113,8 +113,7 @@ export function syncReduxAndRouter(history, store, selectRouterState = SELECT_ST // trigger an unnecessary `pushState` on load lastRoute = initialState - const method = location.action === 'REPLACE' ? replacePath : pushPath; - store.dispatch(method(route.path, route.state, { avoidRouterUpdate: true })); + store.dispatch(pushPath(route.path, route.state, { avoidRouterUpdate: true })); } else if(!locationsAreEqual(getRouterState(), route)) { // The above check avoids dispatching an action if the store is // already up-to-date