redux-effects-fetchr
v1.1.0
Published
yahoo/fetchr binding for redux-effects
Downloads
42
Readme
redux-effects-fetchr
fetchr binding for redux-effects family.
Installation
npm install --save redux-effects-fetchr
Usage
Installing the middleware:
import { createStore, applyMiddleware } from 'redux';
import Fetchr from 'fetchr';
import stepsMiddleware from 'redux-effects-steps';
import fetchrMiddleware from 'redux-effects-fetchr';
import rootReducer from './reducers';
const fetchr = new Fetchr({
xhrPath: '/api'
});
const store = createStore(
rootReducer,
applyMiddleware(
stepsMiddleware,
fetchrMiddleware(fetchr)
)
);
Defining action creators:
import { createAction } from 'redux-actions';
import { steps } from 'redux-effects-steps';
import { fetchrRead } from 'redux-effects-fetchr';
const fetchUserRequest = createAction('FETCH_USER_REQUEST');
const fetchUserSuccess = createAction('FETCH_USER_SUCCESS');
const fetchUserFail = createAction('FETCH_USER_FAIL');
function fetchUser(user) {
return steps(
fetchUserRequest(),
fetchrRead('users', { user }),
[fetchUserSuccess, fetchUserFail]
);
}
Using it:
const promise = store.dispatch(fetchUser({ user }));
API (Action Creators)
fetchrCreate(resource, params = {}, body = {}, config = {})
fetchrCreate({ resource, params = {}, body = {}, config = {} })
Call the create method of a service. See fetchr API docs for more info.
fetchrDelete(resource, params = {}, config = {})
fetchrDelete({ resource, params = {}, config = {} })
Call the delete method of a service. See fetchr API docs for more info.
fetchrRead(resource, params = {}, config = {})
fetchrRead({ resource, params = {}, config = {} })
Call the read method of a service. See fetchr API docs for more info.
fetchrUpdate(resource, params = {}, body = {}, config = {})
fetchrUpdate({ resource, params = {}, body = {}, config = {} })
Call the update method of a service. See fetchr API docs for more info.