# reducer-tools

> redux reducer utilities

Latest version **1.0.0** (published 2019-06-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install reducer-tools
pnpm add reducer-tools
yarn add reducer-tools
bun add reducer-tools
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-06-04 |
| First published | 2018-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yulong Ruan |
| Maintainers | ruanyu1 |
| Keywords | redux, reducer |

## Links

- npm: https://www.npmjs.com/package/reducer-tools
- Repository: https://github.com/ruanyl/reducer-tools
- Issues: https://github.com/ruanyl/reducer-tools/issues
- npm.io page: https://npm.io/package/reducer-tools

## Recent versions

- 1.0.0 (latest) — 2019-06-04
- 1.0.0-beta4 (beta) — 2019-05-02
- 1.0.0-beta2 — 2019-04-14
- 1.0.0-beta1 — 2019-04-12
- 0.2.1 — 2018-06-12
- 0.2.0 — 2018-06-12
- 0.1.0 — 2018-05-01

## README

## reducer tools ![travis](https://travis-ci.org/ruanyl/reducer-tools.svg?branch=master)

Create reducer easily

#### Usage
```typescript
import { createReducer } from 'reducer-tools'

const initialState = { total: 0 }
const increase = s => ({ ...s, total: s.total + 1 })
const decrease = s => ({ ...s, total: s.total - 1 })

const reducer = createReducer(initialState, {
  'increase': increase,
  'decrease': decrease,
})

const a1 = { type: 'increase' }
const s1 = reducer(initialState, a1)
expect(s1.total).toBe(1)
```

#### Use reducer helps
```typescript
import { createReducer, payloadReducer } from 'reducer-tools'

const add = value => state => ({ ...state, total: state.total + value })
const subtract = value => state => ({ ...state, total: state.total - value })
const reducer = createReducer(initialState, {
  'add': payloadReducer(add),
  'subtract': payloadReducer(subtract),
})

const a1 = { type: 'add', payload: 10 }
const s1 = reducer(initialState, a1)
expect(s1.total).toBe(10)
```

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