Created
February 15, 2019 22:48
-
-
Save splincode/fc0155a344739b8bf0ee8f22ca5feefc 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
@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