flux-actions
v0.1.7
Published
Basic class that wrap flux actions.
Downloads
5
Readme
Flux Actions
Basic class that wrap flux actions.
How to use
import Actions from 'flux-actions';
import http from 'fetch-to-request';
import * as actionTypes from './actions-types/users';
class UsersActions extends Actions {
show(userId) {
this.dispatch(actionTypes.SHOW, { userId });
}
loadOne(userId) {
this.dispatchPromise(http.get('/users/' + userId), {
request: actionTypes.LOAD,
request: actionTypes.LOAD_SUCCESS,
request: actionTypes.LOAD_FAIL
}, { userId });
}
}
then when you need call the actions:
import {Dispatcher} from 'flux';
import UsersActions from './actions/UsersActions';
const dispatcher = new Dispatcher();
const usersActions = new UsersActions(dispatcher);
usersActions.show(1);
usersActions.loadOne(1);
Methods
constructor(dispatcher)
Please pass instance of flux Dispatcher
here.
dispatcher
-Dispatcher
instance of fluxDispatcher
dispatch(type, payload)
Dispatch simple action.
type
-string
action typepayload
-object
a payload object
dispatchPromise(promise, types, payload)
Dispatch promise. When dispatchPromise()
is called it put
types.request
action. When promise success it put types.success
action. And when fail - types.fail
action.
promise
-Promise
instance of Promisetypes
-{ request, success, fail }
object with list of types request/success/failpayload
-object
a payload object