NGRX Effect withLatestFrom

时间:2019-02-04 20:21:22

标签: angular ngrx effect

我已经使用withLatestFrom来获取switchMap之前的状态下的商店值。

loadApps$ = this.actions$.pipe(
  ofType(AppActionsTypes.LoadApps),
  withLatestFrom(this.store.select(fromRoot.getCritera)),
  switchMap(([action, request]) => this.service.getApps(request).pipe(
     map((result) => new actions.LoadAppsSuccess(result))
  ))

switchMap([action,request])中的请求以Observable<Criteria>的形式发出,而不仅仅是Criteria对象。我原本希望从中发射出普通物体,并且无法观察到。

getCriteria的类型为MemoizedSelector<object, Criteria>。它创建为

export const moduleState = CreateFeatureSelector<State>('apps');
export const appState = createSelector(moduleState, (state) => state.apps);
export const getCriteria = createSelector(appState, (state) => state.criteria);

0 个答案:

没有答案