Skip to content
This repository has been archived by the owner on Oct 26, 2018. It is now read-only.

Commit

Permalink
Get devtools working
Browse files Browse the repository at this point in the history
  • Loading branch information
kimjoar committed Dec 4, 2015
1 parent ff0f82c commit ef42b0f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand All @@ -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';

Expand Down

0 comments on commit ef42b0f

Please sign in to comment.