From ef42b0fee67b048227b578652c69b4906492d389 Mon Sep 17 00:00:00 2001 From: Kim Joar Bekkelund Date: Fri, 4 Dec 2015 06:54:44 +0100 Subject: [PATCH] Get devtools working --- src/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 8d62e53..8b34983 100644 --- a/src/index.js +++ b/src/index.js @@ -60,7 +60,7 @@ function locationsAreEqual(a, b) { function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) { const getRouterState = () => selectRouterState(store.getState()); - let lastChangeId = 0; + let lastRoute = {}; if(!getRouterState()) { throw new Error( @@ -74,11 +74,14 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) { path: history.createPath(location), state: location.state }; + console.log('HISTORY', route); // Avoid dispatching an action if the store is already up-to-date, // even if `history` wouldn't do anything if the location is the same if(locationsAreEqual(getRouterState(), route)) return; + lastRoute = route; + const updatePath = location.action === 'REPLACE' ? replacePath : pushPath; @@ -88,13 +91,14 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) { const unsubscribeStore = store.subscribe(() => { const routing = getRouterState(); + console.log('STORE', routing); // Only update the router once per `pushPath` call. This is // indicated by the `changeId` state; when that number changes, we // should update the history. - if(lastChangeId === routing.changeId) return; + if(locationsAreEqual(routing, lastRoute)) return; - lastChangeId = routing.changeId; + lastRoute = routing; const method = routing.replace ? 'replaceState' : 'pushState';