javascript - RxJS - how to emit buffer manually / view elements in buffer -


what i'm trying numbers of keyboard events if time between these events less provided. maybe that's not correct approach that's why i'm still in same place.

so first made simple stream filter catch every events interest me. next made second stream , grouped events pairs can measure time stamps. seems it's working pretty numbers of events - after period of time need check if in buffer , if it's there should add string.

code :

const timetowait : number = 500; const keydigitsup$ = observable.fromevent(document, "keyup")   .filter((event:any) => {return ((event.keycode>=48 && event.keycode <=57) || (event.keycode>=96 && event.keycode <=106))});  let bufferedevents = observable.from(keydigitsup$).buffercount(2); let numbers : string = "";  bufferedevents.subscribe((eventarray) => {     if (eventarray[1].timestamp - eventarray[0].timestamp <= timetowait)     {         numbers+=eventarray[0].key + eventarray[1].key;     }     else     {         numbers="";     } }); 

is there way make concept works ? or maybe there better approach i'm missing. made other concepts producing similar results. can of course make work in non-reactive way , subscribe main stream - save last event if exist , compare next , on, since i'm trying learn reactive programming make reactive can.

you're working way hard :-)

const timeout = 500;  keydigitsup$   .buffer(keydigitsup$.debounce(timeout))   .map(events => (events.length <= 1 ? '' : events.map(event => event.key).join(',')))   .subscribe(v => console.log('events timeout ' + timeout + ' msec: '+ v)); 

see working jsbin.

the way works closes buffer (i.e. produces chunk) if of keys not pressed timeout (500 in case) msecs.

i'm not sure wanted key codes, concat them comma delimiter.

note rxjs 5 syntax might different.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -