redux-actions-hub

0.1.2 • Public • Published

redux-actions-hub

Build Status Coverage Status npm version

Share Redux Actions between modules

Installation

npm i --save redux-actions-hub

Usage

Actions

import Actions from 'redux-actions-hub';

// Auto generate action creator
Actions.add('ADD_TODO');

// Action creator
Actions.add('removeTodo', function(id) {
  return {
    type: 'REMOVE_TODO',
    id
  };
});

// With middleware
Actions.add('DELETED_TODO');
Actions.add('REMOTE_FAIL');
Actions.add('remoteDelete', function(id) {
  return dispatch => {
    fetch('https://localhost/todos/delete/' + id)
      .then(response => dispatch(Actions.DELETED_TODO(id)))
      .catch(err => dispatch(Actions.REMOTE_FAIL(err)));
  }
});

dispatch

import {removeTodo, remoteDelete} from 'redux-actions-hub';

// Dispatch
dispatch(removeTodo(1));
dispatch(remoteDelete(1));

API

  1. add(type, actionCreator) Add new action creator to hub
  2. remove(type) Remove action creator from hub
  3. replace(type, actionCreator) Replace action creator from hub with new action creator
  4. reset() Reset actions data

/redux-actions-hub/

    Package Sidebar

    Install

    npm i redux-actions-hub

    Weekly Downloads

    2

    Version

    0.1.2

    License

    MIT

    Last publish

    Collaborators

    • apentle