Angular 5 ngrx 效果无导出成员'ofType'

Angular 5 ngrx Effect no exported member 'ofType'

我正在尝试为我的 ngrx 状态管理器实现 Effects。目前我正在使用 Angular v5.2.1ngrx v4.1.1rxjs v5.5.6。 例如,我尝试了 "older" 方法

@Effect() login$: Observable<Action> = this.actions$.ofType('LOGIN')
.mergeMap(action =>
  this.http.post('/auth', action.payload)
    // If successful, dispatch success action with result
    .map(data => ({ type: 'LOGIN_SUCCESS', payload: data }))
    // If request fails, dispatch failed action
    .catch(() => of({ type: 'LOGIN_FAILED' }))
);

但是我遇到了一个错误 Property 'mergeMap' does not exist on type 'Actions<Action>'。 所以我使用了新的 pipe 方法。问题是当我尝试导入 ofType operator

// ...
import { Action } from '@ngrx/store';
import { Effect, Actions, ofType } from '@ngrx/effects';

import { map, mergeMap, catchError } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';

@Injectable()
export class WifiEffects {

  @Effect()
  getWifiData: Observable<Action> = this.actions$.pipe(
    ofType(WifiTypes.getWifiNetworks),
    mergeMap((action: GetWifiNetworks) =>
      this.mapService.getWifiNetworks().pipe(
        map((data: WifiNetworks) => new GetWifiNetworksSucc(data)),
        catchError(() => of(new GetWifiNetworksErr()))
      )),
  );

  constructor (
    private actions$: Actions,
    private mapService: GoogleMapDataService
  ) {}

}

我收到一个错误Module '".../node_modules/@ngrx/effects/effects"' has no exported member 'ofType'.有什么想法吗?

查看 @ngrx/effects API,没有迹象表明该库已经实现了 ofType 的可出租版本,因此您的第二个实现将无法工作(至少在 ofType 中无效管道)。

您的第一个实现只是缺少 mergeMap

的导入
import 'rxjs/add/observable/mergeMap';

可能还有 mapcatch

import 'rxjs/add/observable/map';
import 'rxjs/add/observable/catch';

如果您想将 ofTypepipe 一起使用,这可能会起作用

@Effect()
getWifiData: Observable<Action> = 
  this.actions$.ofType(WifiTypes.getWifiNetworks)
    .pipe(
      mergeMap((action: GetWifiNetworks) =>
      ...

因为 ofType() returns 已经将 .pipe 添加到其原型的 Observable。


脚注

在查看 github 上的源代码后(截至 2018 年 1 月 22 日),我在 platform/modules/effects/src/index.ts.

找到了可出租 ofType 的导出

但是在安装 @ngrx/effects@latest 时(给我版本 4.1.1)我在安装的 node_modules 文件夹下看不到这个导出参考。

在我的组件中,我也不能使用import { ofType } from '@ngrx/effects';

看起来文档反映的是夜间发布。

https://github.com/ngrx/platform/issues/727

此处提供夜间发布:https://github.com/ngrx/effects-builds