Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create an observable that emits a value every second
- const myInterval = Rx.Observable.interval(1000);
- //Create an observable that emits every time button is clicked
- var button = document.getElementById('clickButton');
- const bufferBy = Rx.Observable.fromEvent(button, 'click');
- /*
- Collect all values emitted by our interval observable until we click document. This will cause the bufferBy Observable to emit a value, satisfying the buffer. Pass us all collected values since last buffer as an array.
- */
- const myBufferedInterval = myInterval.buffer(bufferBy);
- /* ASCII REPRESENTATION
- *
- * --x----x----x----x------->
- *
- * ----c----------c----c---->
- *
- * ----x----------xx---x---->
- */
- //Print values to console
- const subscribe = myBufferedInterval.subscribe(
- val => {
- console.clear();
- console.log('new notification ids', val);
- var numberOfNotifications = val.length;
- console.log('New Notifications ', numberOfNotifications)
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement