javascript - RxJS 5.5 错误 : take is not a function. 链式函数问题

标签 javascript angular rxjs angular5

我正在阅读有关 lettable/pipeable functions in RxJS 的介绍,但没有任何地方表明这可能是链式方法的重大更改。这让我在我们的一个脚本中陷入困境,它在升级后开始抛出错误:

let things = new BehaviorSubject<Thing[]>([]);
things.filter((things) => things.length > 0).take(1).subscribe( ... )

ERROR TypeError: tasks.filter(...).take is not a function

有人可以解释/指出一篇文章解释为什么会发生这种情况吗?顺便说一句,修复方法是将 take(1) 包装在 pipe() 函数中:

things.filter((things) => things.length > 0).pipe(take(1)).subscribe( ... )

..但我不知道为什么突然被迫这样做。

最佳答案

Angular 5 支持 RxJS 5.5,它引入了 lettable 运算符,这应该有助于 tree-shaking 过程,以在应用程序捆绑期间删除未使用的代码。您可以从“rxjs/operators”导入运算符,然后将它们包装到采用可变数量参数的函数 pipe() 中,例如:

import { debounceTime, map} from 'rxjs/operators';
...
let keyupValue$ = keyup$
  .pipe(
     debounceTime(500),
     map(event => event['target'].value))
  .subscribe(val => this.doSomething(val));

我更喜欢旧的语法。但我不认为这是一个重大改变。如果您不使用“rxjs/operators”导入,则可以继续使用旧语法。

关于javascript - RxJS 5.5 错误 : take is not a function. 链式函数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47355760/

相关文章:

javascript - 在 React 应用程序中使用 jquery.scrollbar

javascript - 为 Couchbase 生成唯一的 UInt32 ID

angular - 异常 : Token must be defined! Angular 2

angular - ng build 溢出了很多错误...无法启动我的应用程序

Angular 9 通用 - 运行错误 : can not read property 'type' of undefined - TokenStream

angular - BehaviorSubject保持重置为原始值

javascript - 在 Javascript 中将带引号的变量添加到字符串中

javascript - 括号之间的简单 JavaScript 函数

javascript - 将 javascript 函数动态添加到 Angular 项目

node.js - Angular 6 错误类型错误 : Cannot read property 'navigate' of undefined