Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. //Create an observable that emits a value every second
  2. const myInterval = Rx.Observable.interval(1000);
  3.  
  4. //Create an observable that emits every time button is clicked
  5. var button = document.getElementById('clickButton');
  6. const bufferBy = Rx.Observable.fromEvent(button, 'click');
  7.  
  8. /*
  9. 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.
  10. */
  11. const myBufferedInterval = myInterval.buffer(bufferBy);
  12.  
  13. /* ASCII REPRESENTATION
  14. *
  15. * --x----x----x----x------->
  16. *
  17. * ----c----------c----c---->
  18. *
  19. * ----x----------xx---x---->
  20. */
  21.  
  22. //Print values to console
  23. const subscribe = myBufferedInterval.subscribe(
  24. val => {
  25. console.clear();
  26. console.log('new notification ids', val);
  27. var numberOfNotifications = val.length;
  28. console.log('New Notifications ', numberOfNotifications)
  29. }
  30. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement