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

Commit 6fc0287

Browse files
committed
Get devtools working
1 parent ff0f82c commit 6fc0287

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ function locationsAreEqual(a, b) {
6161
function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
6262
const getRouterState = () => selectRouterState(store.getState());
6363
let lastChangeId = 0;
64+
let firstRoute = undefined;
65+
let lastRoute = {};
6466

6567
if(!getRouterState()) {
6668
throw new Error(
@@ -75,10 +77,17 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
7577
state: location.state
7678
};
7779

80+
if (firstRoute === undefined) {
81+
firstRoute = route;
82+
}
83+
console.log('HISTORY', route);
84+
7885
// Avoid dispatching an action if the store is already up-to-date,
7986
// even if `history` wouldn't do anything if the location is the same
8087
if(locationsAreEqual(getRouterState(), route)) return;
8188

89+
lastRoute = route;
90+
8291
const updatePath = location.action === 'REPLACE'
8392
? replacePath
8493
: pushPath;
@@ -87,14 +96,22 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
8796
});
8897

8998
const unsubscribeStore = store.subscribe(() => {
90-
const routing = getRouterState();
99+
let routing = getRouterState();
100+
console.log('STORE', routing);
101+
102+
if (routing === initialState) {
103+
routing = firstRoute;
104+
}
91105

92106
// Only update the router once per `pushPath` call. This is
93107
// indicated by the `changeId` state; when that number changes, we
94108
// should update the history.
95-
if(lastChangeId === routing.changeId) return;
109+
if(lastChangeId === routing.changeId) {
110+
if(locationsAreEqual(routing, lastRoute)) return;
111+
}
96112

97113
lastChangeId = routing.changeId;
114+
lastRoute = routing;
98115

99116
const method = routing.replace ? 'replaceState' : 'pushState';
100117

0 commit comments

Comments
 (0)