# redux-diet

> Simple Redux Reducer Patterns

Latest version **1.0.6** (published 2018-01-27) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-01-27 |
| First published | 2018-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alex Mouton |
| Maintainers | alexmouton |

## Links

- npm: https://www.npmjs.com/package/redux-diet
- Repository: https://github.com/AlexMouton/redux-diet
- npm.io page: https://npm.io/package/redux-diet

## Recent versions

- 1.0.6 (latest) — 2018-01-27
- 1.0.5 — 2018-01-27
- 1.0.4 — 2018-01-27
- 1.0.2 — 2018-01-27
- 1.0.1 — 2018-01-26
- 1.0.0 — 2018-01-26

## README

# redux-diet
Simple Redux Reducer Patterns.

## Install

```yarn add redux-diet```

## Include

```import * as Diet```

## Apply

```
  combineReducers({
    shownModals: Diet.Object('shownModals'),
    shownModalsStatus: Diet.RequestableStatus('shownModals'),
    notes: Diet.Value('notes', ""),
    visited: Diet.Obj('visited', {}),
  })
```

## Invoke

patterns
 * action words are lower case, simple active verbs
 * your fields are whatever you've got
 * dispatch action key is the same as the leaf


### Value

Value supports `set`
```
  onChange: (notes) => dispatch({type: 'set notes', notes})
```


### Object

* Object supports `set`, `clear`, `merge` at the object level.
* Object supports `set`, `clear` at the field level.


```
dispatch({type: 'set visited firstPage', firstPage: new Date()})
```

### Array

* Array supports `set`
* TODO: set element

### RequestableStatus

Maintains loaded/error state for other resources
* Driven by the key of the other resource
* for key. responds to `request ${key}`, `set ${key}`, `clear ${key}`, `set error ${key}`
* can be given a list of other `reset` action strings that will switch to reset. TODO: Separate this?

Provides two fields: status, error
* status is in ['empty', 'loading', 'clean', 'error']
* error is whatever is sent with 'set error'

caveat:
* `set error ${key}` adds concern if you have an 'error' at the top level
* `set error ${key}` action key is `error` not `${key}`

```
dispatch({type: 'request shownModals'})
fetch(url)
.then(res => res.json())
.catch(error => {
  dispatch({type: 'set error shownModals', error})
)
.then(shownModals => {
  dispatch({type: 'set shownModals', shownModals})
);
```

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