This package has been deprecated

Author message:

This package has been deprecated in favor of: @sepo27/redux-di

redux-exr

0.4.1 • Public • Published

Redux extended reducers

Rationale

A function exCombineReducers() handles depedency injection into reducers in tree.

Usage

exCombineReducers() accepts reducer tree:

const reducerTree = {
  foo: makePlainReducer('initial foo', (state, action) => (
    action.type === 'UPDATE_ACTION' ? 'foo updated' : state
  )),
  bar: makeExReducer(
    'initial foo',
    {foo: '@foo', fox: '@baz.fox'},
    (state, action, {foo, fox}, changes: ExReducerDependenciesChanges) => {
        if (changes.for('foo')) return foo;
        else if (changes.for('fox')) return fox;
        return state;
    }
  ),
  baz: {
    fox: makeExReducer(
        'initial state',
        {foo: '@foo'},
        (state, action, {foo}, changes: ExReducerDependenciesChanges) => {
            return changes.yes() ? foo : state;
        }
    )
  }
};
const rootReducer = exCombineReducers(reducerTree);
  • makePlainReducer(): returns reducer which handles initial state
  • makeExReducer: returns reducer which handles initial state and has dependency specification stored
  • exCombineReducer(): returns a root reducer, which will traverse reducers tree and handle depedency injection.

Key features:

  • all depedencies are resolved in one cycle for one action
  • dependency paths formats:
    • @some.path: absolute path from any place in tree to root state
    • ^sibling.path: path to sibling branch
    • ^^parentSibling.path: path to parent's sibling branch
  • dependent ex reducers and plain reducers can be mixed in any order

Limitations:

  • no cycle depedencies
  • no dependencies to 'ancestors'

Development

  • update version: npm version
  • publish: npm publish

Readme

Keywords

Package Sidebar

Install

npm i redux-exr

Weekly Downloads

0

Version

0.4.1

License

ISC

Unpacked Size

19.6 kB

Total Files

11

Last publish

Collaborators

  • sepo-one
  • sepo27