# redux-optimistic-actions

> Library for creating optimistic, transactional actions that can be reverted.

Latest version **0.0.11** (published 2016-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-optimistic-actions
pnpm add redux-optimistic-actions
yarn add redux-optimistic-actions
bun add redux-optimistic-actions
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2016-08-28 |
| First published | 2016-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jacob Friedmann |
| Maintainers | jacobdfriedmann |

## Links

- npm: https://www.npmjs.com/package/redux-optimistic-actions
- npm.io page: https://npm.io/package/redux-optimistic-actions

## Recent versions

- 0.0.11 (latest) — 2016-08-28
- 0.0.10 — 2016-08-28
- 0.0.9 — 2016-07-20
- 0.0.8 — 2016-07-20
- 0.0.7 — 2016-07-20
- 0.0.6 — 2016-07-20
- 0.0.5 — 2016-07-20
- 0.0.4 — 2016-07-20
- 0.0.3 — 2016-07-20
- 0.0.2 — 2016-07-20
- 0.0.1 — 2016-07-13

## README

# Redux Optimistic Actions

## Installation

```bash
npm install --save redux-optimistic-actions
```

## Example Usage

```js
import { createOptimisticReducer } from 'redux-optimistic-actions';

const initialState = { sum: 0 };

const reducer = createOptimisticReducer((state = initialState, action) => {
    switch (action.type) {
        case 'ADD':
            return { sum: state.sum + action.payload };
        case 'SUBTRACT':
            return { sum: state.sum - action.payload };
        default:
            return state;
    }
});

window.reducer = reducer;

window.action1 = {
    type: 'ADD',
    payload: 1,
    meta: {
        transactionID: 0,
        status: 'pending',
        optimistic: true
    }
};

window.action2 = {
    type: 'ADD',
    payload: 2,
    meta: {
        transactionID: 1,
        status: 'pending',
        optimistic: true
    }
};

window.action3 = {
    type: 'ADD',
    payload: 3
};

window.action2revert = {
    type: 'ADD',
    payload: new Error('bad bad'),
    meta: {
        transactionID: 1,
        status: 'error',
        optimistic: true
    }
};

window.action1commit = {
    type: 'ADD',
    payload: 1,
    meta: {
        transactionID: 0,
        status: 'success',
        optimistic: true
    }
};
```

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