rxjs throttle this.durationSelector不是一个函数

sel*_*ect 7 rxjs typescript rxjs5 ngrx angular

我正在尝试throttle用以下代码存储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(() =>
    ...
  );
Run Code Online (Sandbox Code Playgroud)

这引发了我一个错误

在ThrottleSubscriber.tryDurationSelector(throttle.js:80)TypeError:this.durationSelector不是函数

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

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

mar*_*tin 18

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

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

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

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

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