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

Restore path on Devtools reset #74

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 when resetting 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