redux-rac-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

redux-rac-utils

Build Status codecov

This is a set of utils for creating redux actions creators and reducers.

Getting started

npm install --save redux-rac-utils

Creating a reducer

This helper creates a redux reducer. It relies on the fact that an action object must be FSA compliant.

import { reducerFactory } from 'redux-rac-utils';
 
const initialState = {
  value: 0,
};
 
const reducer = reducerFactory(
  initialState,
  {
    INC: (state, action) => state + action.payload,
    DEC: (state, action) => state - action.payload,
  }
);
 
reducer();
 
/*
{
  value: 0
}
*/
 

Creating an actions creator

import { actionsCreatorFactory } from 'redux-rac-utils';
 
const actionsCreator = actionsCreatorFactory(
  'INC'
);
 
actionsCreator();
 
/*
{
  type: 'INC'
}
*/
 
actionsCreator(5);
 
/*
{
  type: 'INC',
  payload: 5
}
*/
 

You could also provide payloadCreator and metaCreator (similar to redux-actions).

import { actionsCreatorFactory } from 'retax';
 
const actionsCreator = actionsCreatorFactory(
  'INC',
  x => 2 * x,
  y => 3 * y
);
 
actionsCreator();
 
/*
{
  type: 'INC'
}
*/
 
actionsCreator(5);
 
/*
{
  type: 'INC',
  payload: 10,
  meta: 15
}
*/
 

Readme

Keywords

none

Package Sidebar

Install

npm i redux-rac-utils

Weekly Downloads

1

Version

1.0.5

License

MIT

Last publish

Collaborators

  • cnode