Function
Static Public Summary | ||
public |
Decorator that register action type to ActionCreator |
Static Public
public action(args: ...Object | string | undefined): Object | Function source
import action from 'flux-simple-action-creator/src/action.js'
Decorator that register action type to ActionCreator
Example:
class SampleAction extends SimpleActionCreator {
// Register action type and insert arguments - Symbol
@action
method1(type, foo) {
this.dispatch(type, {foo});
}
// Register custom action types and insert arguments
@action('foobarActionType')
method2(type, bar) {
this.dispatch(type, {bar});
}
}
// Action types can access through static variables.
SampleAction.types.method1; // -> Symbol('method1')
SampleAction.types.method2; // -> 'foobarActionType'
// instance variables, too.
const ins = new SampleAction();
assert(ins.types.method1 === SampleAction.types.method1);
assert(ins.types.method2 === SampleAction.types.method2);
// `type` arg is automatically inserted when execute method.
ins.method1('hoge'); // -> received arguments are: Symbol('method1'), 'hoge'
ins.method2('fuga'); // -> received arguments are: 'foobarActionType', 'fuga'