有人可以帮我重构下面的可观察流吗?如果在本地提供者的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));
})
)
}),
);