# @malfaitrobin/redux

> Redux utilities

Latest version **0.0.1** (published 2018-02-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @malfaitrobin/redux
pnpm add @malfaitrobin/redux
yarn add @malfaitrobin/redux
bun add @malfaitrobin/redux
```

## 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.0.1 |
| Published | 2018-02-03 |
| First published | 2018-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Robin Malfait |
| Maintainers | malfaitrobin |

## Links

- npm: https://www.npmjs.com/package/@malfaitrobin/redux
- Repository: https://github.com/RobinMalfait/redux
- Issues: https://github.com/RobinMalfait/redux/issues
- npm.io page: https://npm.io/package/@malfaitrobin/redux

## Dependencies (3)

- [deep-freeze](https://npm.io/package/deep-freeze.md) ^0.0.1
- [flux-standard-action](https://npm.io/package/flux-standard-action.md) ^2.0.1
- [@malfaitrobin/redux-utils](https://npm.io/package/@malfaitrobin/redux-utils.md) ^0.0.1

## Recent versions

- 0.0.1 (latest) — 2018-02-03
- 0.0.1-3 — 2018-01-29
- 0.0.1-2 — 2018-01-29
- 0.0.1-1 — 2018-01-28

## README

<!--
  THIS FILE IS GENERATED
  DO NOT EDIT DIRECTLY
  IF YOU WANT TO MAKE CHANGES PLEASE EDIT THE TEMPLATE FILE: ./scripts/generate-readme/templates/README.md
-->
# Redux utilities

<!-- badge:npm-version -->

<!-- badge:npm-downloads -->

## Installation

With `yarn`:

```shellsession
yarn install @malfaitrobin/redux
```

With `npm`:

```shellsession
npm install --save @malfaitrobin/redux
```

## Table of Contents

* [Action Creators](https://github.com/RobinMalfait/redux#action-creators)
  * [`createAction`](https://github.com/RobinMalfait/redux#createaction)
  * [`createErrorAction`](https://github.com/RobinMalfait/redux#createerroraction)
* [`createReducer`](https://github.com/RobinMalfait/redux#createreducer)
* [`createReducerCreator`](https://github.com/RobinMalfait/redux#createReducerCreator)

### Action creators

> Some utilities to work with action creators. All the actions are [FSA (Flux Standard Actions)](https://github.com/acdlite/flux-standard-action) compliant, if you manage to create an action that is not FSA Compliant, it will throw an error.

#### `createAction`

A utility to create FSA compliant actions using a `type`, optional `payload` and optional `meta` property.

```js
import { createAction } from "@malfaitrobin/redux";

// A simple action
const action = createAction("FOO");
// { type: 'FOO' }

// An action with a payload
const action = createAction("FOO", { value: 5 });
// { type: 'FOO', payload: { value: 5 } }

// An action with a payload and meta information
const action = createAction("FOO", { value: 5 }, { foo: "bar" });
// { type: 'FOO', payload: { value: 5 }, meta: { foo: 'bar' } }
```

#### `createErrorAction`

A utility to create FSA compliant error actions using a `type`, optional `payload` and optional `meta` property.
The payload must be an Error object. It also adds the `{ error: true }` flag.

```js
import { createErrorAction } from "@malfaitrobin/redux";

// A simple action
const action = createErrorAction("FOO");
// { type: 'FOO', error: true }

// An action with a payload
const action = createErrorAction("FOO", new Error("msg"));
// { type: 'FOO', payload: new Error('msg'), error: true }

// An action with a payload and meta information
const action = createErrorAction("FOO", new Error("msg"), {
  foo: "bar"
});
// { type: 'FOO', payload: new Error('msg'), meta: { foo: 'bar' }, error: true }
```

### `createReducer`

> This creates a simple reducer that takes a `pattern` which is an object and an optional `defaultState`. If the type you are handling is not defined, it will return the `state` without touching it.

```js
import { createReducer } from "@malfaitrobin/redux";

const defaultState = {
  value: 0
};

const reducer = createReducer(
  {
    FOO: (state, action) => state
  },
  defaultState
);
```

### `createReducerCreator`

> This is a factory that allows you to create a `createReducer` function but prepared with some middleware. This allows us to keep the `createReducer` clean and simple but it gives the power to write more advanced reducers.

```js
import { createReducerCreator } from "@malfaitrobin/redux";

const createReducer = createReducerCreator(/* ...middleware */);

const defaultState = {
  value: 0
};

const reducer = createReducer(
  {
    FOO: (state, action) => state
  },
  defaultState
);
```

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