Skip to content

apentle/redux-actions-hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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