mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-24 04:25:34 +08:00
Use es6 default values for initial state (#44)
This commit is contained in:
committed by
Satyajit Sahoo
parent
bacc023385
commit
11cb99d8f6
@@ -111,17 +111,18 @@ const AppWithNavigationState = connect(state => ({
|
||||
<AppNavigator navigation={addNavigationHelpers({ dispatch, state: nav })} />
|
||||
));
|
||||
|
||||
const initialNavState = {
|
||||
index: 1,
|
||||
routes: [
|
||||
{ key: 'InitA', routeName: 'Main' },
|
||||
{ key: 'InitB', routeName: 'Login' },
|
||||
],
|
||||
};
|
||||
|
||||
const initialAuthState = { isLoggedIn: false };
|
||||
|
||||
const AppReducer = combineReducers({
|
||||
nav: (state, action) => {
|
||||
if (!state) {
|
||||
state = {
|
||||
index: 1,
|
||||
routes: [
|
||||
{ key: 'InitA', routeName: 'Main' },
|
||||
{ key: 'InitB', routeName: 'Login' },
|
||||
],
|
||||
};
|
||||
}
|
||||
nav: (state = initialNavState, action) => {
|
||||
if (action.type === 'Login') {
|
||||
return AppNavigator.router.getStateForAction({ type: 'Back' }, state);
|
||||
}
|
||||
@@ -130,10 +131,7 @@ const AppReducer = combineReducers({
|
||||
}
|
||||
return AppNavigator.router.getStateForAction(action, state);
|
||||
},
|
||||
auth: (state, action) => {
|
||||
if (!state) {
|
||||
state = { isLoggedIn: false };
|
||||
}
|
||||
auth: (state = initialAuthState, action) => {
|
||||
if (action.type === 'Login') {
|
||||
return { ...state, isLoggedIn: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user