ngrx

How can I customize my reducers using @ngrx/data?

不想你离开。 提交于 2021-02-19 05:19:32
问题 I am learning to use @ngrx/data, it is true that with that library I advance a lot of code, but I am having problems when it comes to personalizing it. I already saw how to add fields to collections export const entityMetadata: EntityMetadataMap = { User: { additionalCollectionState: { testing: null } } }; and set the module here: export class UsersModule { constructor(private eds: EntityDefinitionService) { eds.registerMetadataMap(entityMetadata); } } All good up there, but ..., How can I

Ngrx effect parallel http call

这一生的挚爱 提交于 2021-02-17 02:09:14
问题 I have an effect that should call two different APIs (API1 and API2). Here's the effect $LoadKpiMission = createEffect(() => this.actions$.pipe( ofType<any>(EKpiActions.GetMissionsByStation), mergeMap(action => this.apiCallsService.getKpi(action.payload, '2016-04-18').pipe( map(trips => ({ type: EKpiActions.GetMissionsSuccess, payload: trips })), catchError(() => EMPTY) ) ) ) ); Here's the structure of the service getKpi(station: number, date: string) { let Kpi = `http://192.168.208.25:8998

Ngrx effect parallel http call

左心房为你撑大大i 提交于 2021-02-17 02:08:09
问题 I have an effect that should call two different APIs (API1 and API2). Here's the effect $LoadKpiMission = createEffect(() => this.actions$.pipe( ofType<any>(EKpiActions.GetMissionsByStation), mergeMap(action => this.apiCallsService.getKpi(action.payload, '2016-04-18').pipe( map(trips => ({ type: EKpiActions.GetMissionsSuccess, payload: trips })), catchError(() => EMPTY) ) ) ) ); Here's the structure of the service getKpi(station: number, date: string) { let Kpi = `http://192.168.208.25:8998

Ngrx effect parallel http call

会有一股神秘感。 提交于 2021-02-17 02:07:34
问题 I have an effect that should call two different APIs (API1 and API2). Here's the effect $LoadKpiMission = createEffect(() => this.actions$.pipe( ofType<any>(EKpiActions.GetMissionsByStation), mergeMap(action => this.apiCallsService.getKpi(action.payload, '2016-04-18').pipe( map(trips => ({ type: EKpiActions.GetMissionsSuccess, payload: trips })), catchError(() => EMPTY) ) ) ) ); Here's the structure of the service getKpi(station: number, date: string) { let Kpi = `http://192.168.208.25:8998

Ngrx effect parallel http call

ぐ巨炮叔叔 提交于 2021-02-17 02:07:22
问题 I have an effect that should call two different APIs (API1 and API2). Here's the effect $LoadKpiMission = createEffect(() => this.actions$.pipe( ofType<any>(EKpiActions.GetMissionsByStation), mergeMap(action => this.apiCallsService.getKpi(action.payload, '2016-04-18').pipe( map(trips => ({ type: EKpiActions.GetMissionsSuccess, payload: trips })), catchError(() => EMPTY) ) ) ) ); Here's the structure of the service getKpi(station: number, date: string) { let Kpi = `http://192.168.208.25:8998

ngrx get value in function

泪湿孤枕 提交于 2021-02-11 03:33:51
问题 I am unsure if this is the right thinking, but I just started using ngrx for a project and now everything is an observable. It works well when I use the async pipe in the component view, but I am struggeling when I need the value from the store in code. My current approach is to make a property and subscribe in the ngOnInit to the selector, so I can use the current value of the state in my functions. For example storing configration options (webservice address) and then using that inside a

Multiple dispatches while using ngrx/store

萝らか妹 提交于 2021-02-10 17:07:15
问题 I am working on a sample Angular 2 application , and using ngrx/store , ngrx/effects for state management. Below image depicts one of the screens of my application. In order to display books list , categories and authors from the server, below dispatch calls are made to the store. this.store.dispatch(loadCatgories()); this.store.dispatch(loadAuthors()); this.store.dispatch(loadBooks()); And below the are the related effects @Effect() authors$ = this.actions$ .ofType(AuthorActionTypes.LOAD

How to dispatch an action with current value of state?

落爺英雄遲暮 提交于 2021-02-10 16:40:02
问题 I have an angular component showing items in a list. Each itemn can be selected and the ids of the selected items will be stored in the state. So my state object looks like this f.e.: { items: Item[]; selected: string[] } Now I got an action called DeleteSelectedAction that gets selected as payload. This action will call some WebAPI using an effect and so on. Now I found two ways how I could do this. First: Select selected from store and subscribe to it and pass the value with the action

Unit Testing fromEvent observable with withLatestFrom

こ雲淡風輕ζ 提交于 2021-02-10 13:45:32
问题 I have the following observables: public ngAfterViewInit(): void { fromEvent(this.showFeaturesButton.nativeElement, 'click').pipe( takeUntil(this.ngUnsubscribe), withLatestFrom(this.store.pipe(select(fromClientStorage.getSubscription))) ).subscribe(([_event, subscription]) => { this.featureModal.open(FeatureListComponent, { data: { features: subscription.features }, }); }); } I am trying to test using: it('should call modal when feature button is clicked', () => { const subscription:

cannot unsubscribe ActionsSubject from ngrx/store

冷暖自知 提交于 2021-02-10 06:32:13
问题 I use ngrx/store to implement login actions which gets date from subscribe to a store. The login component is a modal, when I type a wrong password, I get data.type === 'LOGIN_FAILED' , however, when I close the modal and re-open it, the data action is still LOGIN_FAILED instead of INIT . Therefore, the login actions are not unsubscribe, I tried to manually unsubscribe the subscription, but it does not work. How can I unsubscribe the login actions properly? import { Component, OnInit,