0.1.2 • Published 8 years ago

redux-actions-hub v0.1.2

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

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