1.0.0 • Published 8 years ago
create-promise-action-factory v1.0.0
Create promise action factory
Attention! This package created only for test application.
This package helps to dispatch async actions.
Installation
npm install create-promise-action-factory --save
Usage
For correct package working use ES6 transpailer as babeljs
Create your action creators by factory usage like the followings:
import {factory as actionCreatorFactory} from 'create-promise-action';
import axios from 'axios';
const loadUser = actionCreatorFactory('LOAD', (state, payload) => {
return axios.get('/api/userId', payload);
});
loadUser({userId: 1});
Also to apply promise middleware in your redux store:
import {createStore, applyMiddleware, compose} from 'redux';
import {middleware as promiseMiddleware} from 'create-promise-action';
const initialState = {/* .. */};
const enhancer = compose(
// ..
applyMiddleware(promiseMiddleware),
// ..
);
const store = createStore(rootReducer, initialState, enhancer);