# redux-amr

> Redux async middleware and reducer

Latest version **1.0.8** (published 2016-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-amr
pnpm add redux-amr
yarn add redux-amr
bun add redux-amr
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2016-09-28 |
| First published | 2016-09-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | lewis617 |
| Maintainers | lewis617 |

## Links

- npm: https://www.npmjs.com/package/redux-amr
- Repository: https://github.com/lewis617/redux-amr
- Homepage: https://github.com/lewis617/redux-amr#readme
- Issues: https://github.com/lewis617/redux-amr/issues
- npm.io page: https://npm.io/package/redux-amr

## Recent versions

- 1.0.8 (latest) — 2016-09-28
- 1.0.7 — 2016-09-19
- 1.0.6 — 2016-09-18
- 1.0.5 — 2016-09-18
- 1.0.4 — 2016-09-17
- 1.0.3 — 2016-09-16
- 1.0.2 — 2016-09-16
- 1.0.1 — 2016-09-16
- 1.0.0 — 2016-09-16

## README

# Redux async middleware and reducer

[![NPM Version](https://img.shields.io/npm/v/redux-amr.svg?style=flat)](https://www.npmjs.com/package/redux-amr)
[![Build Status](https://travis-ci.org/lewis617/redux-amr.svg?branch=master)](https://travis-ci.org/lewis617/redux-amr)
[![codecov](https://codecov.io/gh/lewis617/redux-amr/branch/master/graph/badge.svg)](https://codecov.io/gh/lewis617/redux-amr)

This package wil help you dispatch async action with less boilerplate.

## Install

```
npm install redux-amr --save
```

## How to use

store/configureStore.js

```js
import { asyncMiddleware } from 'redux-amr';
	
applyMiddleware(thunk, asyncMiddleware)

```

reducers/index.js

```js
import { combineReducers } from 'redux';
import { reducerCreator } from 'redux-amr';

const rootReducer = combineReducers({
  async: reducerCreator()
});

export default rootReducer;
```

actions/index.js

```js
import { ASYNC } from 'redux-amr';

/**
 * This actionCreator will create LOAD and LOAD_SUCCESS,
 * state.async[key] will be 'success'
 */
function success() {
  return {
    [ASYNC]: {
      key: 'key',
      promise: () => Promise.resolve('success')
    }
  }
}

/**
 * This actionCreator will create LOAD and LOAD_FAIL,
 * state.async.loadState.[key].error will be 'fail'
 */
function fail() {
  return {
    [ASYNC]: {
      key: 'key',
      promise: () => Promise.reject('fail')
    }
  }
}
```

## Action and state

* action
    * LOAD: data loading for particular key is started
    * LOAD_SUCCESS: data loading process successfully finished. You'll have data returned from promise
    * LOAD_FAIL: data loading process was failed. You'll have error returned from promise

* state
    * [key]: Data, returned from resolved promise
    * loadState.[key].loading: [key].loading 
    * loadState.[key].loaded: Identifies that promise was resolved
    * loadState.[key].error: Errors, returned from rejected promise
    * loadingNumber: Number of loading


## API

* `[ASYNC]`
    * `key`: String
    * `promise`: Function => Promise
        * `store`(Option): Object
  
* `reducerCreator`: Function => Reducer
    * `reducers`(Option): Object

## License

MIT

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