【发布时间】:2017-08-02 20:00:07
【问题描述】:
可以吗?
更详细的问题
我有这样的事情:
const source = Rx.Observable.interval(500);
const transformed = source.mergeMap(() => Rx.Observable.timer(100));
transformed observable 是 new observable 并且它没有连接到初始 observable source (我无法通过transformed 访问它,我认为)。是否有可能在使用运算符转换后以某种方式获得 initial(在运算符应用之前)可观察?
我的情况
代码:
@AppendLoader()
@Effect()
getFriends$: Observable<Action> = this.actions$
.ofType(friendsActions.GET_FRIENDS)
.switchMap(() => {
return this.friendsService.getFriends()
.map((data: any) => new friendsActions.GetFriendsSuccessAction(data))
.catch(() => of(new friendsActions.GetFriendsFailureAction()));
});
和 AppendLoader:
function AppendLoader() {
return function (target: any, propertyKey: string) {
let observable: any = null;
Object.defineProperty(target, propertyKey, {
configurable: true,
enumerable: true,
get: () => {
console.log('get');
return observable;
},
set: (newObservable) => {
console.log('set', newObservable);
observable = newObservable;
observable
.subscribe((action: any) => {
console.log(action);
});
}
});
};
}
我在那里有三个 observables:
-
this.actions$(所有操作) - 创建自 this.action$
this.action$.ofType(friendsActions.GET_FRIENDS)(friendsActions.GET_FRIENDS类型的可观察对象) - 第三个可观察对象(第二个和
switchMap应用于它)(GetFriendsSuccessAction/GetFriendsFailureAction的可观察对象)
我只能访问装饰器中的第三个可观察对象,因为这个可观察对象位于 getFriends$ 属性中。
我想在 AppendLoader 装饰器中做一些动作。我想订阅列表中的第二个 observable,当发出值时,我想显示负载微调器(例如showLoader())。我想订阅第三个 observable,当成功/失败值发出时,我想隐藏加载微调器。
【问题讨论】:
标签: angular rxjs ngrx ngrx-store ngrx-effects