Last active
April 26, 2018 04:12
-
-
Save taylorc/18ee988fb3c5345c7346a5958e948e91 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 { Action, State, StateContext } from '@ngxs/store'; | |
| import { DecrementCount, IncrementCount } from './home.actions'; | |
| //step 1 | |
| export interface HomeStateModel { | |
| count: number; | |
| } | |
| //step 2 | |
| @State<HomeStateModel>({ | |
| name: 'count', | |
| defaults: { | |
| count: 0 | |
| } | |
| }) | |
| //step 3 | |
| export class HomeState { | |
| @Action(IncrementCount) | |
| incrementCount({ getState, setState }: StateContext<HomeStateModel>) { | |
| const state = getState(); | |
| setState({ | |
| ...state, | |
| count: state.count + 1 | |
| }); | |
| } | |
| @Action(DecrementCount) | |
| decrementCount({ getState, setState }: StateContext<HomeStateModel>) { | |
| const state = getState(); | |
| setState({ | |
| ...state, | |
| count: state.count - 1 | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment