Improve the Redux docs (#1172)

* [ReduxExample] Programmatically generate initial state

* [ReduxExample] Return original state if nextState is null

* [Docs] Add getStateForAction to redux integration example

* [Docs] Add link to ReduxExample app

* [Docs] Give each example a 'DRY' README linking to real docs

* [Docs] Clean up the Contributors guide a bit

* [Docs] Remove numbers from sections in Contributors guide

They don't seem very meaningful, and don't need to be done in order
This commit is contained in:
Kevin Cooper
2017-04-25 05:48:54 -04:00
committed by Mike Grabowski
parent c39dd9d45f
commit 655b46b60b
6 changed files with 50 additions and 43 deletions

View File

@@ -0,0 +1,7 @@
# Navigation Playground Example
A playground for experimenting with react-navigation in a pure-JS React Native app.
## Usage
Please see the [Contributors Guide](https://github.com/react-community/react-navigation/blob/master/docs/guides/Contributors.md#development) for instructions on running these example apps.

View File

@@ -1,17 +0,0 @@
# Navigation Playground Example
A playground for experimenting with react-navigation in a pure-JS React Native app.
## Setup:
```
cd react-navigation
npm install
cd examples/NavigationPlayground
npm install
cd ../..
react-native start
cd examples/NavigationPlayground
react-native run-ios # ignore packager starting error
react-native run-android # ignore packager starting error
```

View File

@@ -0,0 +1,5 @@
# Redux example
## Usage
Please see the [Contributors Guide](https://github.com/react-community/react-navigation/blob/master/docs/guides/Contributors.md#development) for instructions on running these example apps.

View File

@@ -4,27 +4,31 @@ import { NavigationActions } from 'react-navigation';
import { AppNavigator } from '../navigators/AppNavigator';
// Start with two routes: The Main screen, with the Login screen on top.
const initialNavState = {
index: 1,
routes: [
{ key: 'InitA', routeName: 'Main' },
{ key: 'InitB', routeName: 'Login' },
],
};
const initialAuthState = { isLoggedIn: false };
const firstAction = AppNavigator.router.getActionForPathAndParams('Main');
const tempNavState = AppNavigator.router.getStateForAction(firstAction);
const secondAction = AppNavigator.router.getActionForPathAndParams('Login');
const initialNavState = AppNavigator.router.getStateForAction(secondAction, tempNavState);
function nav(state = initialNavState, action) {
let nextState;
switch (action.type) {
case 'Login':
return AppNavigator.router.getStateForAction(NavigationActions.back(), state);
nextState = AppNavigator.router.getStateForAction(NavigationActions.back(), state);
break;
case 'Logout':
return AppNavigator.router.getStateForAction(NavigationActions.navigate({ routeName: 'Login' }), state);
nextState = AppNavigator.router.getStateForAction(NavigationActions.navigate({ routeName: 'Login' }), state);
break;
default:
return AppNavigator.router.getStateForAction(action, state);
nextState = AppNavigator.router.getStateForAction(action, state);
break;
}
// Simply return the original `state` if `nextState` is null or undefined.
return nextState || state;
}
const initialAuthState = { isLoggedIn: false };
function auth(state = initialAuthState, action) {
switch (action.type) {
case 'Login':