Skip to content

Instantly share code, notes, and snippets.

@arturovt
Last active October 29, 2018 20:24
Show Gist options
  • Save arturovt/091dee22a6250a9abfb3954c38ce7ea7 to your computer and use it in GitHub Desktop.
Save arturovt/091dee22a6250a9abfb3954c38ce7ea7 to your computer and use it in GitHub Desktop.
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