Angular Material 文档应用程序中包含以下代码段:
// Combine params from all of the path into a single object.
this.params = combineLatest(
this._route.pathFromRoot.map(route => route.params),
Object.assign);
TSLint 罢工 combineLatest
与此消息:@deprecated — resultSelector no longer supported, pipe to map instead
应该如何解决?
此外,如果您了解所使用的技术,那么一个简单的详细示例将会很棒。
这是一个代码链接:
https://github.com/angular/material.angular.io/blob/master/src/app/pages/component-category-list/component-category-list.ts
最佳答案
combineLatest(observables, resultSelector)
通常可以替换为combineLatest(observables).pipe(
map(resultSelector)
)
但是这是否以相同的方式起作用取决于您的resultSelector
的参数。接受。 combineLatest(observables)
发出一个数组和 RxJs automatically spreads this array当您使用已弃用的 resultSelector 时。return isArray(args) ? fn(...args) : fn(args); // fn is your resultSelector
如Object.assign
返回不同的值,具体取决于您是否提供了一个数组或多个值,您必须手动传播该数组。combineLatest(observables).pipe(
map(items => Object.assign({}, ...items))
)
关于javascript - combineLatest 重构 @deprecated — 不再支持 resultSelector,而是使用管道映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64235967/