加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – rxjs throttle this.durationSelector不是函数

发布时间:2020-12-17 08:21:31 所属栏目:安全 来源:网络整理
导读:我试图用以下代码限制ngrx存储操作更新事件 import 'rxjs/add/operator/throttle'import { Dispatcher,Store } from '@ngrx/store';...static get parameters() { return [[Dispatcher]];}constructor(actions$) {...this.actions$ .filter(action = action.
我试图用以下代码限制ngrx存储操作更新事件
import 'rxjs/add/operator/throttle'
import { Dispatcher,Store } from '@ngrx/store';
...
static get parameters() {
  return [[Dispatcher]];
}
constructor(actions$) {
...

this.actions$
  .filter(action => action.type === this.Actions[`LOAD_USERS_REQUEST`])
  .throttle(1000 /* ms */)
  .subscribe(() =>
    ...
  );

这给我一个错误

at ThrottleSubscriber.tryDurationSelector (throttle.js:80) TypeError:
this.durationSelector is not a function

当我用.throttle(()=> 1000)替换.throttle(1000)时,它会抛出一个不同的错误,清楚地显示油门需要一个功能,而不是我提供的功能.但我想知道为什么因为文档说明油门需要一个数值.

https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/throttle.md

您在 https://github.com/Reactive-Extensions/RxJS上引用的文档页面与RxJS 4有关.由于您使用的是Angular2,因此您使用的是RxJS 5.

运算符throttle()期望作为Observable或Promise的参数.

运算符throttleTime()以毫秒为单位作为参数时间.

所以你应该使用throttleTime(1000).

请注意,使用.throttle(()=> 1000)是非常不同的.您传递一个匿名函数,该函数直接返回1000而不是1000数字.这就是它抛出不同错误的原因.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读