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

Commit

Permalink
Restore path on Devtools reset
Browse files Browse the repository at this point in the history
  • Loading branch information
ellbee committed Dec 4, 2015
1 parent 8422f9f commit 2a00bd7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ function replacePath(path, state, { avoidRouterUpdate = false } = {}) {

// Reducer

const initialState = {
changeId: 1,
path: undefined,
state: undefined,
replace: false
};
// The initial path is needed to be able to reset the state in Devtools but is
// unknown until the history.listen callback set up in syncReduxAndRouter fires
let initialRoute;

function initialState() {
return {
changeId: 1,
state: undefined,
replace: false,
path: initialRoute && initialRoute.path
}
}

function update(state=initialState, { type, payload }) {
function update(state=initialState(), { type, payload }) {
if(type === UPDATE_PATH) {
return Object.assign({}, state, {
path: payload.path,
Expand Down Expand Up @@ -75,6 +81,8 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
state: location.state
};

if(!initialRoute) initialRoute = 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;
Expand Down

0 comments on commit 2a00bd7

Please sign in to comment.