Last active
March 14, 2019 08:23
-
-
Save webmasterdevlin/e670ba73c78daade77c5fbdb555a2b35 to your computer and use it in GitHub Desktop.
NgRx Actions : src/app/actions/hero.actions.ts
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
import { Action } from "@ngrx/store"; | |
import { Hero } from "../models/hero.model"; | |
/* | |
* Action Types | |
*/ | |
export enum HeroActionTypes { | |
LoadHeroes = "[Hero] Load Heroes", | |
LoadHeroesSuccess = "[Hero] Load Heroes Success", | |
LoadHeroesFail = "[Hero] Load Heroes Fail", | |
CreateHero = "[Hero] Create Hero", | |
CreateHeroSuccess = "[Hero] Create Hero Success", | |
CreateHeroFail = "[Hero] Create Hero Fail", | |
UpdateHero = "[Hero] Update Hero", | |
UpdateHeroSuccess = "[Hero] Update Hero Success", | |
UpdateHeroFail = "[Hero] Update Hero Fail", | |
DeleteHero = "[Hero] Delete Hero", | |
DeleteHeroSuccess = "[Hero] Delete Hero Success", | |
DeleteHeroFail = "[Hero] Delete Hero Fail" | |
} | |
export class LoadHeroes implements Action { | |
readonly type = HeroActionTypes.LoadHeroes; // no need for payload | |
} | |
export class LoadHeroesSuccess implements Action { | |
readonly type = HeroActionTypes.LoadHeroesSuccess; | |
constructor(public payload: Hero[]) {} // the payload here is needed by the reducer | |
} | |
export class LoadHeroesFail implements Action { | |
readonly type = HeroActionTypes.LoadHeroesFail; | |
constructor(public payload: any) {} // the payload here is needed by the reducer for setting the error state | |
} | |
export class CreateHero implements Action { | |
readonly type = HeroActionTypes.CreateHero; | |
constructor(public payload: Hero) {} // the payload will be used by the reducer | |
} | |
export class CreateHeroSuccess implements Action { | |
readonly type = HeroActionTypes.CreateHeroSuccess; | |
constructor(public payload: Hero) {} // The payload will be added in the state's Hero[] by the reducer | |
} | |
export class CreateHeroFail implements Action { | |
readonly type = HeroActionTypes.CreateHeroFail; | |
constructor(public payload: any) {} | |
} | |
export class UpdateHero implements Action { | |
readonly type = HeroActionTypes.UpdateHero; | |
constructor(public payload: Hero) {} | |
} | |
export class UpdateHeroSuccess implements Action { | |
readonly type = HeroActionTypes.UpdateHeroSuccess; | |
constructor(public payload: Hero) {} | |
} | |
export class UpdateHeroFail implements Action { | |
readonly type = HeroActionTypes.UpdateHeroFail; | |
constructor(public payload: any) {} | |
} | |
export class DeleteHero implements Action { | |
readonly type = HeroActionTypes.DeleteHero; | |
constructor(public payload: Hero) {} | |
} | |
export class DeleteHeroSuccess implements Action { | |
readonly type = HeroActionTypes.DeleteHeroSuccess; | |
constructor(public payload: string) {} | |
} | |
export class DeleteHeroFail implements Action { | |
readonly type = HeroActionTypes.DeleteHeroFail; | |
constructor(public payload: any) {} | |
} | |
/* | |
* Actions | |
*/ | |
export type HeroActions = | |
| LoadHeroes | |
| LoadHeroesSuccess | |
| LoadHeroesFail | |
| CreateHero | |
| CreateHeroSuccess | |
| CreateHeroFail | |
| UpdateHero | |
| UpdateHeroSuccess | |
| UpdateHeroFail | |
| DeleteHero | |
| DeleteHeroSuccess | |
| DeleteHeroFail; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment