window

signature: window(windowBoundaries: Observable): Observable

Observable of values for window of time.

Examples

Example 1: Open window specified by inner observable

( StackBlitz |
jsBin |
jsFiddle )

  1. import { timer } from 'rxjs/observable/timer';
  2. import { window, scan, mergeAll } from 'rxjs/operators';
  3. //emit immediately then every 1s
  4. const source = timer(0, 1000);
  5. const example = source.pipe(window(interval(3000)));
  6. const count = example.pipe(scan((acc, curr) => acc + 1, 0));
  7. /*
  8. "Window 1:"
  9. 0
  10. 1
  11. 2
  12. "Window 2:"
  13. 3
  14. 4
  15. 5
  16. ...
  17. */
  18. const subscribe = count.subscribe(val => console.log(`Window ${val}:`));
  19. const subscribeTwo = example
  20. .pipe(mergeAll())
  21. .subscribe(val => console.log(val));

Additional Resources


:file_folder: Source Code:
https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/window.ts