Socket
Book a DemoInstallSign in
Socket

@sepo27/redux-di

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sepo27/redux-di

Redux reducers with dependency injection

1.0.0-alpha
latest
Source
npmnpm
Version published
Weekly downloads
460
-14.66%
Maintainers
1
Weekly downloads
 
Created
Source

Redux dependency injection reducers

Rationale

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

Usage

combineDiReducers() accepts reducer tree:

const reducerTree = {
  foo: makePlainReducer('initial foo', (state, action) => (
    action.type === 'UPDATE_ACTION' ? 'foo updated' : state
  )),
  bar: makeDiReducer(
    '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: makeDiReducer(
        'initial state',
        {foo: '@foo'},
        (state, action, {foo}, changes: ExReducerDependenciesChanges) => {
            return changes.yes() ? foo : state;
        }
    )
  }
};
const rootReducer = combineDiReducers(reducerTree);
  • makePlainReducer(): returns reducer which handles initial state
  • makeDiReducer: returns reducer which handles initial state and has dependency specification stored
  • combineDiReducers(): 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

Keywords

redux

FAQs

Package last updated on 30 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.