Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @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);
- }
- }
Add Comment
Please, Sign In to add comment