# redux-describe

> A boilerplate free way to build self documenting reducers with a simple API.

Latest version **0.4.0** (published 2017-10-25) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2017-10-25 |
| First published | 2017-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jonathan Spengeman |
| Maintainers | jspengeman |
| Keywords | redux, reducer, state, functional, immutable, flux, elm, boilerplate free, self documenting |

## Links

- npm: https://www.npmjs.com/package/redux-describe
- Repository: https://github.com/jspengeman/redux-describe
- Issues: https://github.com/jspengeman/redux-describe/issues
- npm.io page: https://npm.io/package/redux-describe

## Dependencies (1)

- [invariant](https://npm.io/package/invariant.md) ^2.2.2

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 0.4.0 (latest) — 2017-10-25
- 0.3.0 — 2017-10-23
- 0.2.0 — 2017-10-22
- 0.1.0 — 2017-10-21

## README

# redux-describe
A boilerplate free way to build self documenting reducers with a simple API.

## Purpose
redux-describe is all about turning your reducers into your documentation to allow people to learn [redux](http://redux.js.org/) easier. In addition, redux-describe allows you to abstract out common operations and reuse them within multiple reducers in a uniform format. 

```
// A classical reducer for a calculator
const calculator = (state = 0, action) => {
  switch(action.type) {
    case 'ADD':
      return state + action.payload
    case 'SUB':
      return state - action.payload
    case 'DIV':
      return state + action.payload
    case 'MULT':
      return state * action.payload
    default:
      return state
  }
}

// The classical calculator reducer can be converted into a more 
// readable self documenting reducer using redux-describe.
const calculator =
  reducer(0)
    .on('ADD').does((state = 0, action) => state + action.payload)
    .on('SUB').does((state = 0, action) => state - action.payload)
    .on('DIV').does((state = 0, action) => state / action.payload)
    .on('MULT').does((state = 0, action) => state * action.payload)
    .build()
```

A single case can be read as: The calculator *reducer* *on* the 'ADD' action *does* the add operation. With non-anonymous functions the readability is increased even more.

redux-describe is a [builder pattern](https://en.wikipedia.org/wiki/Builder_pattern) for your reducers that uses words that allow you to read your reducers like they are just plain english sentences. It replaces switch statements with more terse `on` and `does` statements. 

For a more interesting example take a look at [relationalEntities.js](https://github.com/jspengeman/redux-describe/blob/master/examples/relationalEntities.js) example. The more advanced example demonstrates how generic `operations` can be shared amongst other reducers more readable reducers.

## Installation
To install redux-describe run the following command

```
npm install redux-describe --save
```

Or if you prefer yarn use this command instead

```
yarn add redux-describe
```

## Documentation
Full API documentation will completed on a 1.0 release. The API should be considered unstable until a formal 1.0 release is made.

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