Skip to content

Latest commit

 

History

History
72 lines (52 loc) · 1.22 KB

notes.md

File metadata and controls

72 lines (52 loc) · 1.22 KB

Patterns

  1. A React Component:
ReactComponent = function(props) {
    const state = {}
    return <View/>
}
  1. Define reducer with initial state and actions that it has to handle:
const reducer = (currentState = {}, action) => nextState
  1. Split the reducers based on state/sub state that they manage for seperation of concerns:
const subReducer1 = (subState1 = {}, action) => subState1
const subReducer2 = (subState2 = {}, action) => subState2
...
  1. Combine reducers into one reducer:
const combinedReducer = combineReducers({
    subState1: subReducer1,
    subState2: subReducer2,
    ...
})
  1. Create store with combinedReducer as input:
const store = createStore(combinedReducer)
  1. Create Root component that takes store as input:
const Root = ({store}) => (
    <Provider store={store}>
        <Router history={browserHistory}>
            <Route path='/(:filter)' component={AppComponent} />
        </Router>
    </Provider>
)
  1. AppComponent:
const TodoApp = () => (
    <div>
        <Header />
        <MainContent />
        <Footer />
    </div>
)

getSelector(subState, field, ...fields) => subState[field]

store.dispatch(action) -> reducers()