rxjs throttle this.durationSelector 不是函数
rxjs throttle this.durationSelector is not a function
我正在尝试 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(() =>
...
);
这会给我一个错误
at ThrottleSubscriber.tryDurationSelector (throttle.js:80) TypeError:
this.durationSelector is not a function
当我用 .throttle(() => 1000)
替换 .throttle(1000)
时,它会抛出一个不同的错误,清楚地表明 throttle 需要一个函数,而不是我提供的函数。但我想知道为什么,因为文档指出 throttle 需要一个数值。
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)
非常不同。您传递一个匿名函数 returns 1000
而不是直接传递 1000
数字。这就是它抛出不同错误的原因。
我正在尝试 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(() =>
...
);
这会给我一个错误
at ThrottleSubscriber.tryDurationSelector (throttle.js:80) TypeError: this.durationSelector is not a function
当我用 .throttle(() => 1000)
替换 .throttle(1000)
时,它会抛出一个不同的错误,清楚地表明 throttle 需要一个函数,而不是我提供的函数。但我想知道为什么,因为文档指出 throttle 需要一个数值。
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)
非常不同。您传递一个匿名函数 returns 1000
而不是直接传递 1000
数字。这就是它抛出不同错误的原因。