# redux-commands

> a redux middleware that allows your dispatch commands

Latest version **2.1.4** (published 2021-10-12) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.4 |
| Published | 2021-10-12 |
| First published | 2019-09-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | yuankui |
| Maintainers | yuankui |
| Keywords | redux, commands, middleware, redux-middleware, fsa, flux |

## Links

- npm: https://www.npmjs.com/package/redux-commands
- Repository: https://github.com/yuankui/redux-commands
- Homepage: https://github.com/yuankui/redux-commands#readme
- Issues: https://github.com/yuankui/redux-commands/issues
- npm.io page: https://npm.io/package/redux-commands

## Dependencies (1)

- [redux](https://npm.io/package/redux.md) ^4.0.4

## 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

- 2.1.4 (latest) — 2021-10-12
- 2.0.5 — 2019-11-28
- 2.0.4 — 2019-11-27
- 2.0.3 — 2019-11-26
- 2.0.2 — 2019-11-26
- 2.0.1 — 2019-11-26
- 1.0.14 — 2019-11-26
- 1.0.13 — 2019-11-26
- 1.0.12 — 2019-11-26
- 1.0.5 — 2019-09-05
- 1.0.4 — 2019-09-05
- 1.0.3 — 2019-09-05
- 1.0.2 — 2019-09-05
- 1.0.1 — 2019-09-05
- 1.0.0 — 2019-09-05

## README

# Redux-Commands
Use Redux with Commands

## Installation 
```sh
npm install redux-commands --save
yarn add redux-commands
```

## Usage

### Basic Usage

```typescript
import {applyMiddleware, createStore} from "redux";
import {Command, commandMiddleware, enhanceCommandReducer, Mapper} from "redux-commands";

class GrownOldCommand extends Command<any> {
    by: number;

    constructor(by: number) {
        super();
        this.by = by;
    }

    name(): string {
        return "my-command";
    }

    process(state: any): any {
        return {
            ...state,
            age: state.age + this.by,
        }
    }
}

function initReducer() {
    return {
        name: "yuankui",
        age: 30,
    };
}

let store = createStore(enhanceCommandReducer(initReducer), applyMiddleware(commandMiddleware));
console.log("init state");
console.log(store.getState());
// output:
//    { name: 'yuankui', age: 30 }

console.log("dispatch new GrownOldCommand(3)");
store.dispatch(new GrownOldCommand(3));

console.log("current state");
console.log(store.getState());
// output:
//    { name: 'yuankui', age: 33 }
```

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