Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { createStore, applyMiddleware, compose } from 'redux'
- import { browserHistory } from 'react-router'
- import { routerMiddleware } from 'react-router-redux'
- import { makeRootReducer } from '../reducer'
- const makeStore = (initialState = {}) => {
- const middleware = [
- routerMiddleware(browserHistory)
- // other middlewares
- ]
- const store = createStore(
- makeRootReducer(),
- initialState,
- compose(
- applyMiddleware(...middleware)
- )
- )
- store.asyncReducers = {}
- return store
- }
- module.exports = makeStore
- import { combineReducers } from 'redux'
- import { routerReducer } from 'react-router-redux'
- import { combineForms } from 'react-redux-form'
- import { initialLoginState } from './components/forms/login'
- const makeRootReducer = (asyncReducers) => {
- const customReducers = {
- // other of my own imported reducers
- }
- const forms = {
- login: initialLoginState
- }
- const allReducers = {
- ...customReducers,
- forms: combineForms(forms, 'forms'),
- routing: routerReducer,
- ...asyncReducers
- }
- return combineReducers(allReducers)
- }
- // mutate the store just this once.
- const injectReducer = (store, { key, reducer }) => {
- store.asyncReducers[key] = reducer // eslint-disable-line no-param-reassign
- store.replaceReducer(makeRootReducer(store.asyncReducers))
- }
- module.exports = {
- makeRootReducer,
- injectReducer
- }
- <Form model='forms.login' onSubmit={login => console.debug(login)}>
- <label>Email</label>
- <Control.text model='.username' />
- <label>Password</label>
- <Control type='password' model='.password' />
- <button type="submit">Login</button>
- </Form>
- state:
- forms:
- login:
- username: ''
- password: ''
- forms:
- $form:
- focus: false
- # ... etc
- login:
- $form:
- focus: false
- # ... etc
- username: ''
- password: ''
- const allReducers = {
- ...customReducers,
- forms: combineForms(forms),
- routing: routerReducer,
- ...asyncReducers
- }
- state:
- forms:
- login:
- username: ''
- password: ''
- forms:
- $form:
- focus: false
- # ... etc
- login:
- $form:
- focus: false
- # ... etc
- username: ''
- password: ''
- state:
- forms:
- login:
- $form:
- focus: false
- # ... etc
- username: ''
- password: ''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement