Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/recruit-tech/redux-effects-fetchr
yahoo/fetchr binding for redux-effects
https://github.com/recruit-tech/redux-effects-fetchr
Last synced: about 11 hours ago
JSON representation
yahoo/fetchr binding for redux-effects
- Host: GitHub
- URL: https://github.com/recruit-tech/redux-effects-fetchr
- Owner: recruit-tech
- License: mit
- Created: 2016-07-22T12:56:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-13T12:48:44.000Z (over 7 years ago)
- Last Synced: 2024-04-25T10:43:01.425Z (7 months ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 10
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-effects-fetchr
[fetchr](https://www.npmjs.com/package/fetchr)
binding for
[redux-effects](https://www.npmjs.com/package/redux-effects)
family.## Installation
```
npm install --save redux-effects-fetchr
```## Usage
Installing the middleware:
```javascript
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:
```javascript
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:
```javascript
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](https://github.com/yahoo/fetchr/blob/master/docs/fetchr.md#createresource-params-body-config-callback)
for more info.### `fetchrDelete(resource, params = {}, config = {})`
### `fetchrDelete({ resource, params = {}, config = {} })`Call the delete method of a service. See
[fetchr API docs](https://github.com/yahoo/fetchr/blob/master/docs/fetchr.md#deleteresource-params-config-callback)
for more info.### `fetchrRead(resource, params = {}, config = {})`
### `fetchrRead({ resource, params = {}, config = {} })`Call the read method of a service. See
[fetchr API docs](https://github.com/yahoo/fetchr/blob/master/docs/fetchr.md#readresource-params-config-callback)
for more info.### `fetchrUpdate(resource, params = {}, body = {}, config = {})`
### `fetchrUpdate({ resource, params = {}, body = {}, config = {} })`Call the update method of a service. See
[fetchr API docs](https://github.com/yahoo/fetchr/blob/master/docs/fetchr.md#updateresource-params-body-config-callback)
for more info.