Last active
March 14, 2019 23:56
-
-
Save webmasterdevlin/344fccf6831df698f85cf813402f7280 to your computer and use it in GitHub Desktop.
NgRx Selectors and Store : src/app/reducers/index.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 { ActionReducerMap, createSelector, MetaReducer } from "@ngrx/store"; | |
import { environment } from "../../environments/environment"; | |
import { heroReducer, HeroState } from "./hero.reducer"; | |
import { villainReducer, VillainState } from "./villain.reducer"; | |
export interface State { | |
heroes: HeroState; | |
villains: VillainState; | |
} | |
/* | |
This reducers combine the two reducers which is the heroReducer and the villainReducer | |
*/ | |
export const reducers: ActionReducerMap<State> = { | |
heroes: heroReducer, | |
villains: villainReducer | |
}; | |
export const metaReducers: MetaReducer<State>[] = !environment.production | |
? [] | |
: []; | |
// selector, selecting the state.heroes | |
export const selectHeroesState = (state: State) => state.heroes; | |
export const selectHero = createSelector( | |
selectHeroesState, | |
(state: HeroState) => state.heroes | |
); | |
// selector, selecting the state.villains | |
export const selectVillainsState = (state: State) => state.villains; | |
export const selectVillain = createSelector( | |
selectVillainsState, | |
(state: VillainState) => state.villains | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment