# redux-observable-process-fetch

> processes for redux-observable

Latest version **0.1.3** (published 2016-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-observable-process-fetch
pnpm add redux-observable-process-fetch
yarn add redux-observable-process-fetch
bun add redux-observable-process-fetch
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2016-05-30 |
| First published | 2016-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Ivan Starkov |
| Maintainers | istarkov |
| Keywords | redux, observable, middleware, process, processes |

## Links

- npm: https://www.npmjs.com/package/redux-observable-process-fetch
- Repository: https://github.com/istarkov/redux-observable-process-fetch
- Homepage: https://github.com/istarkov/redux-observable-processes#readme
- Issues: https://github.com/istarkov/redux-observable-processes/issues
- npm.io page: https://npm.io/package/redux-observable-process-fetch

## Dependencies (1)

- [rxjs](https://npm.io/package/rxjs.md) ^5.0.0-beta.8

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2016-05-30
- 0.1.2 — 2016-05-30
- 0.1.1 — 2016-05-29
- 0.1.0 — 2016-05-25

## README

# redux-observable-process-fetch

This library is a [redux-observable](https://github.com/redux-observable/redux-observable) middleware.
And as `redux-observable` is a middleware itself it is a middleware for middleware.

This middleware add caching, refetching, pre and post loading actions support
for async data loading services like `Observable.ajax` or any other service with signature
`(...args: Array<any>) => Observable<any>`.

# Example

The best example is a [tests](./tests/createFetchProcess.spec.js)

Initialize redux with `redux-observable` and `redux-observable-process-fetch`

```javascript
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/dom/ajax';
import { createStore, applyMiddleware } from 'redux';
import { reduxObservable, combineDelegators } from 'redux-observable';
import { createFetchProcess } from 'redux-observable-process-fetch';

const ctreateStoreWithReduxObservableMiddleware = (reducer) => {
  const processor = combineDelegators(
    createFetchProcess({ fetch: (type, id) => Observable.ajax(`http://blbla/${type}/${id}`) })
  );
  const middleware = reduxObservable(processor);
  const store = createStore(reducer, applyMiddleware(middleware));
  return store;
};
```

Create action creator

```javascript
export const loadMySuperObject = (...args) => ({
  type: FETCH_DATA,
  meta: { type: 'SUPER_OBJECT_LOAD', cache: true },
  payload: args,
});
```

Use `loadMySuperObject` as usual in redux.

# What you will get

For each action with type `FETCH_DATA`, like this

```javascript
const fetchDataAction = {
  type: FETCH_DATA,
  meta: { type: ON_FETCH_SOMETHING_COMPLETE, cache: false },
  payload: [1, 2]
}
```

It dispatches `LOADING_START` and `LOADING_END` actions before data fetch starts and after it end.

On fetch complete it dispatches action

```javascript
{
  type: fetchDataAction.meta.type,
  payload: fetchResult,
  meta: fetchDataAction.meta
}
```

and on fetch error

```javascript
{
  type: fetchDataAction.meta.type,
  payload: error,
  error: true,
  meta: fetchDataAction.meta
}
```

If `FETCH_DATA` action meta has `cache: false` property, and action with same
`payload` and `meta.type` has already been successfully processed,
it does nothing (_as data is already in redux store_).

It `fetch` again if there where fetch error at previous call.

If `FETCH_DATA` action meta has `cache: true` property, it always fetch `data` again,
cancelling previous `FETCH_DATA` action with same `payload` and `meta.type`.

If such actions are called simultaneously first action does not run at all.

If sequentially action `LOADING_CANCEL` will be run.

Look at [tests](./tests/createFetchProcess.spec.js) for more examples.

# Install

```
npm install --save redux-observable-process-fetch
```

---
_Source: https://npm.io/package/redux-observable-process-fetch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
