# vanilla-create-reducer

> Create a reducer from an object of action types and reducer functions. To be used with any JS framework.

Latest version **1.1.0** (published 2020-08-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install vanilla-create-reducer
pnpm add vanilla-create-reducer
yarn add vanilla-create-reducer
bun add vanilla-create-reducer
```

## 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.1.0 |
| Published | 2020-08-20 |
| First published | 2020-08-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Harry G. Withers |
| Maintainers | hargwit |
| Keywords | javascript, reducer |

## Links

- npm: https://www.npmjs.com/package/vanilla-create-reducer
- Repository: https://github.com/hargwit/vanilla-create-reducer
- Homepage: https://github.com/hargwit/vanilla-create-reducer#readme
- Issues: https://github.com/hargwit/vanilla-create-reducer/issues
- npm.io page: https://npm.io/package/vanilla-create-reducer

## Recent versions

- 1.1.0 (latest) — 2020-08-20
- 1.0.0 — 2020-08-20

## README

# create-vanilla-reducer ![Travis CI badge](https://travis-ci.com/hargwit/vanilla-create-reducer.svg?branch=master)

Create a reducer from an object of reducer functions keyed by the action type. To be used with any JS framework.

An alternative pattern to the classic Redux style switch case.

```js
import createReducer from "vanilla-create-reducer";

const ACTIONS = {
  toggle: "__toggle__",
  set: "__set__",
};

function toggle(state, action) {
  return { ...state, on: !state.on };
}

function set(state, action) {
  return { ...state, on: action.on };
}

const reducer = createReducer({
  [ACTIONS.toggle]: toggle,
  [ACTIONS.set]: set,
});
```

To see `createReducer` in action, check out [this React sandbox](https://codesandbox.io/s/vanilla-create-reducer-example-wdrh5)

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