Angularjs 角度1.x使用优化中的RxJs观测值

Angularjs 角度1.x使用优化中的RxJs观测值,angularjs,rxjs,Angularjs,Rxjs,我正在用RxJs创建一个Angular 1.6应用程序来扩展我的服务,但我觉得我创建的其中一个东西可以写得更好 因此,我的列表函数get是一个过滤器对象,它通过其他服务或服务本身中的主题进行更新。因此,我将它们结合起来,并订阅它 但是我想在调用列表之后更新一个公共的可观察对象。但是做一个.subscribe()然后再做一个.next()感觉很奇怪。还有别的方法吗 执行此操作的代码如下所示: constructor(private $log: ILogService, pr

我正在用RxJs创建一个Angular 1.6应用程序来扩展我的服务,但我觉得我创建的其中一个东西可以写得更好

因此,我的列表函数get是一个过滤器对象,它通过其他服务或服务本身中的主题进行更新。因此,我将它们结合起来,并订阅它

但是我想在调用列表之后更新一个公共的可观察对象。但是做一个
.subscribe()
然后再做一个
.next()
感觉很奇怪。还有别的方法吗

执行此操作的代码如下所示:

constructor(private $log: ILogService,
            private $q: IQService,
            private http: Http,
            private appConfig: AppConfig,
            private searchService: SearchService) {
  this.pagingSubject = new Subject<Page>();
  this.applicableMachinesSubject = new Subject<ApplicableMachineFilterResponse>(); // Will store all incoming http requests
  this.applicableMachine$ = Observable.from(this.applicableMachinesSubject);

  Observable
    .combineLatest(this.searchService.searchTermsHash$.throttleTime(250), this.pagingSubject)
    .share()
    .subscribe((next) => {
      // If less then 1 subscriber don't continue
      if (this.applicableMachinesSubject.observers.length < 1) {
        return;
      }
      const filter: ApplicableMachineFilter = assign(new ApplicableMachineFilter, next[0], next[1]);
      this.list(filter)
          .subscribe((f) => {
            this.applicableMachinesSubject.next(f);
          });
    });
}

private list(filter?: ApplicableMachineFilter): Observable<ApplicableMachineFilterResponse> {
  const validFilter: ApplicableMachineFilter = this.validate(filter);
  return this.http
             .get(`${this.appConfig.api}/ApplicableMachines`, {params: validFilter})
             .map((res) => (res as any).data);
}
constructor(私有$log:ILogService,
私人$q:IQService,
私有http:http,
私有appConfig:appConfig,
私人搜索服务:搜索服务){
this.paginsubject=新主题();
this.applicatablemachinessubject=new Subject();//将存储所有传入的http请求
this.applicatablemachine$=从(this.applicatablemachines主题)可观察到的;
可观察
.CombineTest(this.searchService.searchTermsHash$.throttleTime(250),this.pagingSubject)
.share()
.订阅((下一步)=>{
//如果少于1个订户,则不继续
如果(此.applicatablemachinessubject.observators.length<1){
返回;
}
常量过滤器:AppliebleMachineFilter=assign(新AppliebleMachineFilter,下一个[0],下一个[1]);
此.list(过滤器)
.订阅((f)=>{
本.应用机械主体.下一(f);
});
});
}
私有列表(筛选器?:AppliebleMachineFilter):可观察{
const validFilter:AppliebleMachineFilter=this.validate(过滤器);
返回此文件。http
.get(`this.appConfig.api}/applicatablemachines`,{params:validFilter})
.map((res)=>(res如有)。数据);
}
我们重写了angular 1的$http服务来处理可观测数据