Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@workpop/dux

Package Overview
Dependencies
Maintainers
14
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@workpop/dux

HOC Redux Functions

  • 2.1.2
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
14
Weekly downloads
 
Created
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

Package last updated on 08 Aug 2017

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