Rxjs throttle this.durationSelector is not a function

I am trying to execute throttle ngrx save event update events with the following code

 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(() => ... ); 

it causes an error

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

When I replace .throttle(1000) with .throttle(() => 1000) , it throws another error that clearly shows that the throttle is expecting a function, not the one I provide. But I wonder why, since the documentation states that the throttle is expecting a numerical value.

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

+7
angular typescript rxjs rxjs5 ngrx
source share
1 answer

The documentation page that you link to https://github.com/Reactive-Extensions/RxJS is related to RxJS 4. Since you are using Angular2, you are using RxJS 5.

The throttle() operator expects Observable or Promise as an argument.

The throttleTime() operator takes a time in milliseconds as an argument.

So you should use throttleTime(1000) .

Note that using .throttle(() => 1000) very different. You pass an anonymous function that returns the number 1000 instead of 1000 . Therefore, another error occurs.

+15
source share

All Articles