Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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
  • npm
  • Socket score

Version published
Maintainers
1
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

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc