Guest User

Untitled

a guest
Feb 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. @State<Hero[]>({
  2. name: 'heroes',
  3. defaults: []
  4. })
  5. export class HeroesState {
  6.  
  7. @Action(AddHero)
  8. private addHeroByState(ctx: StateContext<Hero[]>, { hero }: AddHero) {
  9. ctx.setState([ ...ctx.getState(), hero ]);
  10. }
  11.  
  12. @Action(DeleteHero)
  13. private deleteHeroByState(ctx: StateContext<Hero[]>, { id }: DeleteHero) {
  14. ctx.setState(ctx.getState().filter((hero: Hero) => hero.id !== id));
  15. }
  16.  
  17. @Action(AddHeroes)
  18. private addHeroesByState(ctx: StateContext<Hero[]>, { heroes }: AddHeroes) {
  19. ctx.setState(heroes);
  20. }
  21.  
  22. }
Add Comment
Please, Sign In to add comment