2.1.4 • Published 3 years ago

redux-commands v2.1.4

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

Redux-Commands

Use Redux with Commands

Installation

npm install redux-commands --save
yarn add redux-commands

Usage

Basic Usage

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 }
2.1.4

3 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

1.0.14

4 years ago

2.0.1

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago