This file contains 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
{ | |
"javascript.validate.enable": false, | |
"flow.pathToFlow": "${workspaceRoot}/node_modules/.bin/flow", | |
"flow.stopFlowOnExit": true, | |
"flow.enabled": true, | |
"flow.useNPMPackagedFlow": false, | |
"flow.showStatus": true, | |
"flow.showUncovered": false, | |
"flow.runOnEdit": true, | |
"flow.useLSP": false |
This file contains 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
[ignore] | |
.*/node_modules/fbjs/.* | |
[options] | |
esproposal.class_static_fields=enable | |
esproposal.class_instance_fields=enable | |
[untyped] | |
.*/node_modules/.* |
This file contains 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
prev() { | |
this.store.dispatch(new ChangePage(Pagination.PREV)); | |
} | |
next() { | |
this.store.dispatch(new ChangePage(Pagination.NEXT)); | |
} |
This file contains 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
ngOnInit() { | |
this.heroes$ = this.store.select(getHeroes); | |
this.isFirst$ = this.store.select(getIsFirstPage); | |
this.isLast$ = this.store.select(getIsLastPage); | |
this.isLoading$ = this.store.select(getIsLoading); | |
this.store.dispatch(new FetchHeroes()); | |
} |
This file contains 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
export const getHeroesState = createFeatureSelector<fromHeroes.State>('heroes'); | |
export const getHeroes = createSelector(getHeroesState, state => state.data); | |
export const getIsLoading = createSelector(getHeroesState, state => state.isLoading); | |
export const getCurrentPage = createSelector(getHeroesState, state => state.page); | |
export const getIsFirstPage = createSelector(getHeroesState, state => !state.previous); | |
export const getIsLastPage = createSelector(getHeroesState, state => !state.next); |
This file contains 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
export class HeroesEffects { | |
@Effect() | |
fetch$: Observable<HeroesActions> = this.actions$ | |
.ofType(HeroesActionTypes.FetchHeroes) | |
.pipe( | |
withLatestFrom(this.store), | |
switchMap(([action, state]) => | |
this.service.getHeroes(getCurrentPage(state)).pipe( | |
map(data => new FetchHeroesSuccess(data)), | |
catchError(err => of(new FetchHeroesError(err))) |
This file contains 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
export function reducer(state = initialState, action: HeroesActions): State { | |
switch (action.type) { | |
case HeroesActionTypes.FetchHeroes: | |
return { | |
...state, | |
isLoading: true, | |
error: null | |
}; |
This file contains 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
export const initialState: State = { | |
isLoading: false, | |
error: null, | |
data: [], | |
next: null, | |
previous: null, | |
page: 1 | |
}; |
This file contains 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
export interface State { | |
isLoading: boolean; | |
error: HttpErrorResponse | null; | |
data: Hero[] | null; | |
next: string | null; | |
previous: string | null; | |
page: number; | |
} |
This file contains 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
export enum HeroesActionTypes { | |
FetchHeroes = '[Heroes] Fetch Heroes', | |
FetchHeroesSuccess = '[Heroes] Load Heroes Success', | |
FetchHeroesError = '[Heroes] Load Heroes Error', | |
ChangePage = '[Heroes] Change page' | |
} | |
export enum Pagination { | |
NEXT, | |
PREV |