问题描述
角度材料文档应用程序包含以下代码段:
The angular material documentation app has the following snippet in it:
// 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
与此消息:
TSLint strikesout combineLatest
with this message:
@deprecated — 不再支持 resultSelector,改为使用管道映射
应该如何解决?
此外,如果您了解所使用的技术,一个带有详细说明的简单示例会很棒.
Also if you understand the technique being used, a simple example with elaboration would be awesome.
这是一个代码链接:
推荐答案
combineLatest(observables, resultSelector)
通常可以替换为
combineLatest(observables).pipe(
map(resultSelector)
)
但是这是否以相同的方式工作取决于您的 resultSelector
接受哪些参数.combineLatest(observables)
发出一个数组和 RxJs 会在您使用已弃用的 resultSelector 时自动扩展此数组.
But whether this works in the same way depends on what parameters your resultSelector
accepts. combineLatest(observables)
emits an array and RxJs automatically spreads this array when you're using the deprecated resultSelector.
return isArray(args) ? fn(...args) : fn(args); // fn is your resultSelector
As Object.assign
返回不同的值,具体取决于您提供的是数组还是必须手动传播数组的多个值.
As Object.assign
returns different values depending on whether you provide an array or multiple values you have to spread the array manually.
combineLatest(observables).pipe(
map(items => Object.assign({}, ...items))
)
这篇关于针对@deprecated 的 combineLatest 重构 — 不再支持 resultSelector,改为使用管道映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!