Socket
Socket
Sign inDemoInstall

@workpop/dux

Package Overview
Dependencies
5
Maintainers
17
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @workpop/dux

HOC Redux Functions


Version published
Maintainers
17
Install size
2.41 MB
Created

Readme

Source

dux

Workpop Redux Tools and Composers

These composers can be used in the style of a higher order function to add common reducer transforms to redux stores.

Usage

import { withSet } from '@workpop/dux';

const SET = 'SET';

const reducer = withSet(SET)((state = 'bar', action = {}) => {
  switch(action.type) {
    // other reducer cases
    default:
      return state;
  }
});

// from redux
const store = createStore(reducer);

// actions like normal
store.dispatch({
    type: SET,
    data: 'foo',
});

// state will be "foo"

Using compose from recompose or flowRight from lodash will let you chain enhancers together.

import { flowRight } from 'lodash';
import { withSet, withClear } from '@workpop/dux';

const SET = 'SET';
const CLEAR = 'CLEAR';

const enhancer = flowRight(
  withSet(SET),
  withClear(CLEAR),
);

const reducer = enhancer((state = 'bar', action = {}) => {
  switch(action.type) {
      // other reducer cases
    default:
        return state;
  }
});

const store = createStore(reducer);

store.dispatch({
    type: SET,
    data: 'foo',
});

// state will be "foo"

store.dispatch({
    type: CLEAR,
});

// state will be "bar"

Finally, composeReducer passes its last argument to the previous combined composers.

import { composeReducer, withSet } from '@workpop/dux';

const SET = 'SET';
const CLEAR = 'CLEAR';

const reducer = composeReducer(
  withClear(CLEAR),
  withSet(SET),
  // reducer is the last argument
  (state = 'bar', action = {}) => {
    switch(action.type) {
      // other reducer cases
      default:
        return state;
    }
  },
);

const store = createStore(reducer);

store.dispatch({
    type: SET,
    data: 'foo',
});

// state will be "foo"

store.dispatch({
    type: CLEAR,
});

// state will be "bar"

Enhancers

TODO

Lists

TODO

Common

TODO

FAQs

Last updated on 01 May 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc