Last active
October 29, 2018 20:24
-
-
Save arturovt/091dee22a6250a9abfb3954c38ce7ea7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { State, StateContext } from '@ngxs/store'; | |
import { Receiver } from '@ngxs-labs/emitter'; | |
export interface CounterStateModel { | |
value: number; | |
} | |
@State<CounterStateModel>({ | |
name: 'counter', | |
defaults: { | |
value: 0 | |
} | |
}) | |
export class CounterState { | |
@Receiver() | |
public static increment({ setState, getState }: StateContext<CounterStateModel>): void { | |
setState({ | |
value: getState().value + 1 | |
}); | |
} | |
@Receiver({ type: '[Counter] Decrement' }) | |
public static decrement({ setState, getState }: StateContext<CounterStateModel>): void { | |
setState({ | |
value: getState().value - 1 | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment