1.1.1 • Published 5 years ago
typescript-actions v1.1.1
typescript-actions
Typescript actions/reducers based on classes
Installation
// NPM
npm install --save typescript-actions
// YARN
yarn add typescript-actions
Modify .tsconfig
{
"compilerOptions": {
...
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
...
}
}
Add simple store
import {action, ActionBase, apiAction, nameof, PromiseOrVoid} from 'typescript-actions/dist';
export interface ICounterStore extends IStoreBase {
result: number;
}
export const initialCounterStore: ICounterStore = {
...baseInitialStore,
result: 0,
};
Action example
import {action, ActionBase, apiAction, nameof, PromiseOrVoid} from 'typescript-actions/dist';
export interface ICounterActions {
increment(): void;
decrement(): void;
}
export class CounterActions extends ActionBase implements ICounterActions {
@action()
public increment(): void {
this.dispatch({
name: this.actionName,
payload: null
});
}
@action()
public decrement(): void {
this.dispatch({
name: this.actionName,
payload: null
});
}
public getStoreName(): string {
return nameof<IGlobalStore>('counter') as string;
}
}
Reducer example
import {ReducerBase} from 'typescript-actions/dist';
export class CounterReducer extends ReducerBase<ICounterStore> implements ICounterActions {
public getStoreName() {
return nameof<IGlobalStore>('counter');
}
@reducer()
public increment(): void {
this.setState({
result: this.store.result + 1
});
}
@reducer()
public decrement(): void {
this.setState({
result: this.store.result - 1
});
}
}
1.1.1
5 years ago
1.0.78
5 years ago
1.0.77
5 years ago
1.0.76
5 years ago
1.0.75
5 years ago
1.0.74
5 years ago
1.0.73
5 years ago
1.0.72
5 years ago
1.0.71
5 years ago
1.0.70
5 years ago
1.0.69
5 years ago
1.0.68
5 years ago
1.0.67
5 years ago
1.0.66
5 years ago
1.0.65
5 years ago
1.0.64
5 years ago
1.0.63
5 years ago
1.0.62
5 years ago
1.0.61
5 years ago
1.0.60
5 years ago
1.0.59
5 years ago
1.0.58
5 years ago
1.0.57
5 years ago
1.0.56
5 years ago
1.0.55
5 years ago
1.0.54
5 years ago
1.0.53
5 years ago
1.0.52
5 years ago
1.0.51
5 years ago
1.0.50
5 years ago
1.0.49
5 years ago
1.0.48
5 years ago
1.0.47
5 years ago
1.0.46
5 years ago
1.0.45
5 years ago
1.0.44
5 years ago
1.0.43
5 years ago
1.0.42
5 years ago
1.0.41
5 years ago
1.0.40
5 years ago
1.0.39
5 years ago
1.0.35
5 years ago
1.0.32
5 years ago
1.0.30
5 years ago
1.0.29
5 years ago
1.0.27
5 years ago
1.0.12
5 years ago
1.0.10
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 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