Modules: app/util/createViewReducer

Methods


createViewReducer(childReducerMap)

This utility creates a special type of reducer to facilitate the functionality of the generic view reducers like entityViewReducer and entityListViewReducer. The syntax is very similar to the redux combineReducers util.

Child reducers passed to createViewReducer are only called under either of the following conditions:

  • the child reducer itself is also created with createViewReducer()
  • an action is dispatched with a 'view' property on 'meta' with the exact location of the child reducer in the view state tree. For example, the child reducer 'articles' in a view reducer nested under 'pages.home' will only be called if the action contains the following data: { meta: {view: 'pages.home.articles'} }.

**important: ** because this util does not output a regular reducer function, the returned view reducer should only be nested under other reducers created with createViewReducer().

It is possible to also include regular reducer logic in the resulting view reducer. To do this, pass a regular reducer to the returned function. The view reducer will be merged with the regular reducer.

Parameters:
Name Type Description
childReducerMap

An object of child view reducers that should be combined into this reducer. See redux combineReducers

Source:
Example
// import child view reducers
import modal from './modalReducer';
import pages from './pagesReducer';

// create a regular reducer
const myReducer = handleActions( ... );

// create a view reducer
const myViewReducer = createViewReducer({
  modal,
  pages,
});

// export the view reducer merged with the regular reducer
export default myViewReducer(myReducer);