Skip to content

Instantly share code, notes, and snippets.

@splincode
Created February 15, 2019 22:48
Show Gist options
  • Save splincode/fc0155a344739b8bf0ee8f22ca5feefc to your computer and use it in GitHub Desktop.
Save splincode/fc0155a344739b8bf0ee8f22ca5feefc to your computer and use it in GitHub Desktop.
@State<Hero[]>({
name: 'heroes',
defaults: []
})
export class HeroesState {
@Action(AddHero)
private addHeroByState(ctx: StateContext<Hero[]>, { hero }: AddHero) {
ctx.setState([ ...ctx.getState(), hero ]);
}
@Action(DeleteHero)
private deleteHeroByState(ctx: StateContext<Hero[]>, { id }: DeleteHero) {
ctx.setState(ctx.getState().filter((hero: Hero) => hero.id !== id));
}
@Action(AddHeroes)
private addHeroesByState(ctx: StateContext<Hero[]>, { heroes }: AddHeroes) {
ctx.setState(heroes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment