Skip to content

kaizenplatform/kaizen-redux-action-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kaizen-redux-action-types

The helper for Redux action types constants.

Installation

$ npm install kaizenplatform/kaizen-redux-action-types --save

Usage

import Types, { async } from 'kaizen-redux-action-types';

First, define action types constants:

// actions/actionTypes.js
import Types, { async } from 'kaizen-redux-action-types';

const types = new Types(
  'SORT',
  async('FETCH_USER'),
);

export default types;

Then, use get() to get the defined constants:

// actions/user.js
import types from './actionTypes';

export function request() {
  return {
    type: types.get('FETCH_USER_REQUEST'),
  };
}

export function success(response) {
  return {
    type: types.get('FETCH_USER_SUCCESS'),
    payload: {
      response: response.data,
    },
  };
}

export function error(errors) {
  return {
    type: types.get('FETCH_USER_FAILURE'),
    payload: {
      errors,
    },
    error: true,
  };
}

API Reference

new Types(types)

const types = new Types(
  'SORT',
  async('FETCH_USER'),
);

async(type)

The shortcut to define async action types. It returns three types with suffix.

  • ${type}_REQUEST
  • ${type}_SUCCESS
  • ${type}_FAILURE

get(type)

types.get('SORT'); // returns `SORT`
types.get('FETCH_USER_SUCCESS'); // returns `FETCH_USER_SUCCESS`
types.get('UNDEFINED_ACTION'); // An exception is thrown.

Development

Building

$ npm run build

Running tests

$ npm test

To run test on every file change:

$ npm run test:watch

Lint

$ npm run lint

Note

kaizen-redux-action-types is inspired by https://github.com/ripeworks/redux-action-types

About

The helper for Redux action types constants

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published