流操作的顺序不正确

时间:2017-11-14 21:30:47

标签: rxjs rxjs5 ngrx ngrx-effects

有人可以帮我重构下面的可观察流吗?如果在本地提供者的getPreferences期间发生异常,远程提供者仍然会出现getPreferences吗?

谢谢!

    @Effect() load$: Observable<Action> = this._actions$
    .ofType<Load>(LOAD)
    .pipe(
        switchMap(() => {
            return this._localProvider.getPreferences()
                .pipe(
                    tap((preferences: Preferences) => {
                        this._store.dispatch(new LoadSuccess(preferences));
                    }),
                    switchMap((preferences: Preferences) => {
                        return this._remoteProvider.getPreferences()
                            .pipe(
                                filter((remotePref: Preferences) => {
                                    return remotePref.timestamp$ > preferences.timestamp$;
                                }),
                                map((remotePref: Preferences) => {
                                    return new LoadSuccess(remotePref);
                                }),
                                catchError(error => {
                                    return of(new LoadError(error));
                                })
                            )
                    }),
                    catchError(error => {
                        return of(new LoadError(error));
                    })
                )
        }),
    );

0 个答案:

没有答案