简体   繁体   中英

RxJs v5 in Angular5 - clickStream.bufer( () => clickStream.throttleTime(250)) etc fails

How can I do the following?

let button = document.querySelector('.this');
let clickStream = Observable.fromEvent(button, 'click');
let multiClickStream = clickStream
   .buffer(() => { return clickStream.throttleTime(250); } )
   .map(function(list) { return list.length; })
   .filter(function(x) { return x >= 2; });

The error message is:

TS2345: argument of type '()=> void' is not assignable to paramter of type Observabl. Property '_isScalar' is missing in type ()=>void

Alternatives like ".buffer(function() { return clickStream.throttleTime(250); }) " give a similar error.

I also tried throttle(250) , but that does not work neither.

It looks like you wanted to use bufferWhen that accepts a function as an argument.

Otherwise just pass the Observable directly to buffer without wrapping it:

...
.buffer(clickStream.throttleTime(250))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM