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

dead-simple-redux-helper

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dead-simple-redux-helper

Dead simple redux helper (actions and reducers only)

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Dead simple redux helpers

Installation

$ npm install --save dead-simple-redux-helper

Usage

import { createAction, createReducer } from 'dead-simple-redux-helper';

Creating standard Flux action creators

const MY_ACTION = 'myAction';


// returns flux action creator:
const someAction = createAction(MY_ACTION);

/* returns standard flux action:
{
  type: MY_ACTION,
  payload: 'hello'
}
*/
const action = someAction('hello');

Creating standard Flux action creators with argument transformer

const MY_COMPLEX_ACTION = 'myComplexAction';

// pass property names, which will be used to create `payload` object
const complexAction = createAction(MY_COMPLEX_ACTION, ['name', 'lastName', 'age']);

/* returns
{
  type: MY_COMPLEX_ACTION,
  payload: {
    name: 'John',
    lastName: 'Smith',
    age: 42
  }
}
*/
const action = complexAction('John', 'Smith', 42);

/* returns
{
  type: MY_COMPLEX_ACTION,
  payload: {
    name: 'John',
    lastName: undefined,
    age: undefined
  }
}
*/
const action = complexAction('John');

Creating reducers

const MY_ACTION = 'myAction';
const MY_COMPLEX_ACTION = 'myComplexAction';

const initialState = {
  name: '',
  lastName: '',
  age: 0,
}

// returns state if action.type does not match
const myReducer = createReducer(initialState, {
  // every handler has 2 params: `state = initialState`, and `action.payload`
  [MY_ACTION](state, payload) {
    // do something
    return newState
  },
  // { name, lastName, age } = payload (see above)
  [MY_COMPLEX_ACTION](state, payload) {
    // do something
    return newState
  }
})

License

MIT

FAQs

Package last updated on 28 Feb 2016

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