UNPKG

reactant-module

Version:

A module model for Reactant

46 lines 1.1 kB
import { AnyAction } from 'redux'; import { ThisService } from '../interfaces'; /** * ## Description * * It is used for compatibility with redux actions, * when a class state with actions is being migrated from the Redux boilerplate code to the Reactant. * And it's often used in conjunction with `createState()`. * * ## Example * * ```ts * const type = 'count_increase'; * * interface CountAction { * type: typeof type; * state: number; * } * * @injectable() * class Counter { * @state * count = createState<CountAction['state'], CountAction>( * ($state = 0, $action) => ($action.type === type ? $action.state : $state) * ); * * increase() { * dispatch<CountAction>(this, { * type, * state: this.count + 1, * }); * } * } * * const app = createApp({ * modules: [], * main: Counter, * render: () => {}, * }); * * app.instance.increase(); * expect(app.instance.count).toBe(1); * ``` */ export declare const dispatch: <T extends AnyAction = AnyAction>(target: ThisService, action: T) => void; //# sourceMappingURL=dispatch.d.ts.map