Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne committed Jun 21, 2018
1 parent dde0918 commit 76da804
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/routers/SwitchRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,39 +74,39 @@ export default (routeConfigs, config = {}) => {
};
}

return {
childRouters,
function getNextState(prevState, possibleNextState) {
if (!prevState) {
return possibleNextState;
}

let nextState;
if (prevState.index !== possibleNextState.index && resetOnBlur) {
const prevRouteName = prevState.routes[prevState.index].routeName;
const nextRoutes = [...possibleNextState.routes];
nextRoutes[prevState.index] = resetChildRoute(prevRouteName);

getInitialState() {
const routes = order.map(resetChildRoute);
return {
routes,
index: initialRouteIndex,
isTransitioning: false,
...possibleNextState,
routes: nextRoutes,
};
},

getNextState(prevState, possibleNextState) {
if (!prevState) {
return possibleNextState;
}
} else {
nextState = possibleNextState;
}

let nextState;
if (prevState.index !== possibleNextState.index && resetOnBlur) {
const prevRouteName = prevState.routes[prevState.index].routeName;
const nextRoutes = [...possibleNextState.routes];
nextRoutes[prevState.index] = resetChildRoute(prevRouteName);
return nextState;
}

return {
...possibleNextState,
routes: nextRoutes,
};
} else {
nextState = possibleNextState;
}
function getInitialState() {
const routes = order.map(resetChildRoute);
return {
routes,
index: initialRouteIndex,
isTransitioning: false,
};
}

return nextState;
},
return {
childRouters,

getActionCreators(route, stateKey) {
return {
Expand All @@ -117,7 +117,7 @@ export default (routeConfigs, config = {}) => {

getStateForAction(action, inputState) {
let prevState = inputState ? { ...inputState } : inputState;
let state = inputState || this.getInitialState();
let state = inputState || getInitialState();
let activeChildIndex = state.index;

if (action.type === NavigationActions.INIT) {
Expand Down Expand Up @@ -154,7 +154,7 @@ export default (routeConfigs, config = {}) => {
if (activeChildState && activeChildState !== activeChildLastState) {
const routes = [...state.routes];
routes[state.index] = activeChildState;
return this.getNextState(prevState, {
return getNextState(prevState, {
...state,
routes,
});
Expand Down Expand Up @@ -204,7 +204,7 @@ export default (routeConfigs, config = {}) => {
if (newChildState && newChildState !== childState) {
const routes = [...state.routes];
routes[activeChildIndex] = newChildState;
return this.getNextState(prevState, {
return getNextState(prevState, {
...state,
routes,
index: activeChildIndex,
Expand Down Expand Up @@ -232,15 +232,15 @@ export default (routeConfigs, config = {}) => {
...lastRoute,
params,
};
return this.getNextState(prevState, {
return getNextState(prevState, {
...state,
routes,
});
}
}

if (activeChildIndex !== state.index) {
return this.getNextState(prevState, {
return getNextState(prevState, {
...state,
index: activeChildIndex,
});
Expand Down Expand Up @@ -284,7 +284,7 @@ export default (routeConfigs, config = {}) => {
}

if (index !== state.index || routes !== state.routes) {
return this.getNextState(prevState, {
return getNextState(prevState, {
...state,
index,
routes,
Expand Down

0 comments on commit 76da804

Please sign in to comment.