windowCount

signature: windowCount(windowSize: number, startWindowEvery: number): Observable

Observable of values from source, emitted each time provided count is fulfilled.

windowCount - 图1

Examples

Example 1: Start new window every x items emitted

( StackBlitz |
jsBin |
jsFiddle )

  1. import { interval } from 'rxjs/observable/interval';
  2. import { windowCount, mergeAll, tap } from 'rxjs/operators';
  3. //emit every 1s
  4. const source = interval(1000);
  5. const example = source.pipe(
  6. //start new window every 4 emitted values
  7. windowCount(4),
  8. tap(_ => console.log('NEW WINDOW!'))
  9. );
  10. const subscribeTwo = example
  11. .pipe(
  12. //window emits nested observable
  13. mergeAll()
  14. /*
  15. output:
  16. "NEW WINDOW!"
  17. 0
  18. 1
  19. 2
  20. 3
  21. "NEW WINDOW!"
  22. 4
  23. 5
  24. 6
  25. 7
  26. */
  27. )
  28. .subscribe(val => console.log(val));

Additional Resources


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