代码之家  ›  专栏  ›  技术社区  ›  Phaze

不推荐使用角形6 ng皮棉组合测试

  •  31
  • Phaze  · 技术社区  · 7 年前

    我最近从角度5更新到角度6。

    我收到这个警告 combineLatest is deprecated: resultSelector no longer supported, pipe to map instead .Rxjs版本为6.1.0,tslint版本为5.10.0,Angular CLI版本为6.0.0,Typescript版本为2.7.2。我是这样使用它的:

    const a$ = combineLatest(
      this.aStore.select(b.getAuth),
      this.cStore.select(b.getUrl),
      (auth, url) => ({auth, url}),
    );
    

    我也这样试过:

    empty().pipe(
    combineLatest(...),
      ...
    )
    

    但这给了我: combineLatest is deprecated: Deprecated in favor of static combineLatest empty也不赞成使用静态版本。

    8 回复  |  直到 4 年前
        1
  •  79
  •   Abinesh Devadas    4 年前

    不推荐使用CombineTest:不再支持resultSelector,改为使用管道映射

    以上警告建议删除您在CombineTest observable中提供的最后一个函数resultSelector,并将其作为map操作符的一部分提供,如下所示

    const a$ = combineLatest(
      this.aStore.select(b.getAuth),
      this.cStore.select(b.getUrl)
    );
    
    const result$ = a$.pipe(
      map(results => ({auth: results[0], url: results[1]}))
    )
    

    更新时间:

    如果你看到 combineLatest is deprecated: Pass arguments in a single array instead 然后只需添加[]:

    const a$ = combineLatest([
      this.aStore.select(b.getAuth),
      this.cStore.select(b.getUrl)
    ]);
        
    const result$ = a$.pipe(
      map(results => ({auth: results[0], url: results[1]}))
    )
    
        2
  •  11
  •   Rui Marques    3 年前

    不幸的是,如果从运算符导入CombineTest,也可能会出现tslint错误:

    import { combineLatest } from 'rxjs/operators';
        
    combineLatest(...array);
    

    而不是

    import { combineLatest } from 'rxjs';
        
    combineLatest(...array);
    
        3
  •  5
  •   jenson-button-event    5 年前

    与不推荐的版本不同, combineLatest 接受 大堆 属于 Observable 并返回一个数组,其中包含每个数组中的最新值。每一条河流都必须屈服 组合测试 屈服。

    fruitType$ = combineLatest([this.entity$, this.datasetStateService.get$('Fruits')])
      .pipe(map(data => {
        const entity = data[0];
        const dataset = data[1];
        return {
           isApple: (dataset.find(ds => ds.label === 'Apple') as DataItem).id === entity.fruitId,
           isOrange: (dataset.find(ds => ds.label === 'Orange') as DataItem).id === entity.fruitId
        }
    }));
    
        4
  •  1
  •   Basavaraj Bhusani    7 年前

    对于 trailing comma 错误,请删除后面的逗号 (auth, url) => ({auth, url})

    const a$ = combineLatest(
      this.aStore.select(b.getAuth),
      this.cStore.select(b.getUrl),
      (auth, url) => ({auth, url}),  // Remove this comma.
    );
    

    对于 missing import 错误,请确保已导入文件中使用的所有外部var或类。

    例如,在本例中,如果尚未导入 combineLatest ,然后导入

    import { combineLatest } from 'rxjs'; // For RxJS 6.x
    
    import { combineLatest } from 'rxjs/operators'; // For RxJS 5.x
    
        5
  •  1
  •   Valeriy Katkov    5 年前

    在我的例子中,这是因为我显式设置了泛型参数,所以 combineLatest 已选择过载。为了摆脱警告,我改了

    combineLatest<void>([
        firstObservable$,
        secondObservable$
    ]);
    

    combineLatest([
        firstObservable$,
        secondObservable$
    ]).pipe(
        mapTo(undefined)
    );
    
        6
  •  0
  •   Prezes    4 年前

    我会这样解决:

    auth$ = this.aStore.select(b.getAuth);
    url$ = this.cStore.select(b.getUrl);
    
    combinedResult$ = combineLatest([this.auth$, this.url$]).pipe(
        map(([auth, url]) => ({auth, url}))
    )
    
        7
  •  0
  •   Trevor    4 年前

    此错误也可能是由于传入 Subscription 项目,而不是实际观察到的,哈哈。(我在这一点上真的很马虎。)

    错误的

    const foo = Foo$.subscribe(f => {
      // do something with f here
    })
    
    const bar = Bar$.subscribe(b => {
      // do something with b here
    })
    
    combineLatest([foo, bar]).subscribe(([f, b]) => {
      // do something after both foo$ and bar$ have emitted something
    })
    

    对的

    const foo$ = Foo$.pipe(
      tap(f => {
        // do something with f here
      })
    )
    
    const bar$ = Bar$.pipe(
      tap(b => {
        // do something with b here
      })
    )
    
    combineLatest([foo$, bar$]).subscribe(([f, b]) => {
      // do something after both Foo$ and Bar$ have emitted something
    })
    
        8
  •  0
  •   Mo.    4 年前

    我用去润滑的CombineTest来组合这两个观测值。路线paramMap+此。路线查询参数映射:

    combineLatest(this.route.paramMap, this.route.queryParamMap)
      .subscribe(combined => {
        const idFollower = combined[0].get('id');
        const page = combined[1].get('page');
      })