Created
May 9, 2020 15:54
-
-
Save splincode/f8be28c6ed70d20bc90884809ea34610 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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