Share Redux Actions between modules
npm i --save redux-actions-hub
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));
- add(type, actionCreator) Add new action creator to hub
- remove(type) Remove action creator from hub
- replace(type, actionCreator) Replace action creator from hub with new action creator
- reset() Reset actions data