Skip to content

Instantly share code, notes, and snippets.

@splincode
Created May 9, 2020 15:54
Show Gist options
  • Save splincode/f8be28c6ed70d20bc90884809ea34610 to your computer and use it in GitHub Desktop.
Save splincode/f8be28c6ed70d20bc90884809ea34610 to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { State } from '@ngxs/store';
interface CountModel {
value: number;
}
export class IncrementAction {
public static type: string = '[Increment]';
constructor(public value: number) {}
}
@State<CountModel>({
name: 'counter',
defaults: { value: 0 }
})
@Injectable()
export class CounterState {
@Action(IncrementAction)
public increment(ctx: StateContext<CountModel>, { value }: IncrementAction): void {
ctx.setState((state) => ({ value: state.value + value }));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment