-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
36 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,41 @@ | ||
import isEqual from 'lodash.isequal'; | ||
import { NavigationActions, StackActions } from 'react-navigation'; | ||
import navigationStore from './navigationStore'; | ||
import * as ActionConst from './ActionConst'; | ||
import { getActiveState, popPrevious } from './State'; | ||
|
||
export function reducer(state, action) { | ||
const { type, routeName } = action; | ||
if (type === ActionConst.POP_TO) { | ||
let nextScene = ''; | ||
let newState = state; | ||
let currentState = state; | ||
while (newState && nextScene !== routeName) { | ||
newState = navigationStore.getStateForAction(StackActions.pop(), currentState); | ||
if (newState) { | ||
nextScene = getActiveState(newState).routeName; | ||
if (isEqual(currentState, newState)) { | ||
console.warn(`popTo called with an unknown routeName: ${routeName}`); | ||
break; | ||
} | ||
if (nextScene !== routeName) { | ||
currentState = newState; | ||
export default function createReducer(navigationStore) { | ||
return (state, action) => { | ||
const { type, routeName } = action; | ||
if (type === ActionConst.POP_TO) { | ||
let nextScene = ''; | ||
let newState = state; | ||
let currentState = state; | ||
while (newState && nextScene !== routeName) { | ||
newState = navigationStore.getStateForAction(StackActions.pop(), currentState); | ||
if (newState) { | ||
nextScene = getActiveState(newState).routeName; | ||
if (isEqual(currentState, newState)) { | ||
console.warn(`popTo called with an unknown routeName: ${routeName}`); | ||
break; | ||
} | ||
if (nextScene !== routeName) { | ||
currentState = newState; | ||
} | ||
} | ||
} | ||
return nextScene === routeName ? newState : state; | ||
} | ||
return nextScene === routeName ? newState : state; | ||
} | ||
if (type === ActionConst.REPLACE) { | ||
const newState = navigationStore.getStateForAction( | ||
NavigationActions.navigate({ | ||
routeName, | ||
params: action.params, | ||
}), | ||
state, | ||
); | ||
const res = popPrevious(newState, routeName); | ||
return res; | ||
} | ||
return navigationStore.getStateForAction(action, state) || state; | ||
} | ||
|
||
export default function createReducer() { | ||
return reducer; | ||
if (type === ActionConst.REPLACE) { | ||
const newState = navigationStore.getStateForAction( | ||
NavigationActions.navigate({ | ||
routeName, | ||
params: action.params, | ||
}), | ||
state, | ||
); | ||
const res = popPrevious(newState, routeName); | ||
return res; | ||
} | ||
return navigationStore.getStateForAction(action, state) || state; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters