Skip to content

Latest commit

History

History

helper-store

Folders and files

NameName
Last commit message
Last commit date

parent directory

..

dreact/helper-store

Organize store for redux with redux-saga.

Exported

  • default

    import makeStoreConfigurer from 'dreact/helper-store'
    
    export default makeStoreConfigurer(params)
    
    export default makeStoreConfigurer({
      initialState: {},
    
      sagas: [require('./custom-saga.js').default],
    
      reducers: {
        form: require('redux-form').reducer,
      },
    
      reducerMiddleware: appReducer => (state, action) => {
        if (action.type === logoutAction.SUCCESS) {
          return appReducer(undefined, action)
        }
    
        return appReducer(state, action)
      },
    })

    Params

    • initialState (optional, object, default {})

      Initial state of the entire store

    • sagas (optional, array)

      Contains references to necessary sagas which will be combined then

      sagas: [require('src/lib/custom-saga.js').default]

      In addition to that the list will be extended with sagas defined inside collections. It's done by babel.

    • reducers (optional, object)

      Contains references to necessary reducers which will be combined then

      reducers: {
        form: require('redux-form').reducer,
      }

      In addition to that the object will be extended with reducers defined inside collections. It's done by babel. Reducers specified manually will override automatically added.

    • reducerMiddleware (optional, function)

      In case you'd like to handle actions and changes in reducer you can do that here by creating a middleware on top of main reducer.

      reducerMiddleware: appReducer => (state, action) => {
        // Define custom behavior for actions with type 'LOGOUT'
        if (action.type === 'LOGOUT') {
          return appReducer(undefined, action)
        }
      
        // Proceed with default behavior:
        return appReducer(state, action)
      }
  • effects

    It's an alias of used redux-saga/effects inside.

  • RESTART

    It's an action that can be dispatched in store. It's been designed to restart sagas (stop everything and run again).

    import { RESTART, effects } from 'dreact/helper-store'
    
    function* someSaga() {
      yield effects.put(RESTART)
    }
  • useDispatch

  • useSelector

  • Provider