window.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Observable } from '../Observable';
  2. import { OperatorFunction } from '../interfaces';
  3. /**
  4. * Branch out the source Observable values as a nested Observable whenever
  5. * `windowBoundaries` emits.
  6. *
  7. * <span class="informal">It's like {@link buffer}, but emits a nested Observable
  8. * instead of an array.</span>
  9. *
  10. * <img src="./img/window.png" width="100%">
  11. *
  12. * Returns an Observable that emits windows of items it collects from the source
  13. * Observable. The output Observable emits connected, non-overlapping
  14. * windows. It emits the current window and opens a new one whenever the
  15. * Observable `windowBoundaries` emits an item. Because each window is an
  16. * Observable, the output is a higher-order Observable.
  17. *
  18. * @example <caption>In every window of 1 second each, emit at most 2 click events</caption>
  19. * var clicks = Rx.Observable.fromEvent(document, 'click');
  20. * var interval = Rx.Observable.interval(1000);
  21. * var result = clicks.window(interval)
  22. * .map(win => win.take(2)) // each window has at most 2 emissions
  23. * .mergeAll(); // flatten the Observable-of-Observables
  24. * result.subscribe(x => console.log(x));
  25. *
  26. * @see {@link windowCount}
  27. * @see {@link windowTime}
  28. * @see {@link windowToggle}
  29. * @see {@link windowWhen}
  30. * @see {@link buffer}
  31. *
  32. * @param {Observable<any>} windowBoundaries An Observable that completes the
  33. * previous window and starts a new window.
  34. * @return {Observable<Observable<T>>} An Observable of windows, which are
  35. * Observables emitting values of the source Observable.
  36. * @method window
  37. * @owner Observable
  38. */
  39. export declare function window<T>(windowBoundaries: Observable<any>): OperatorFunction<T, Observable<T>>;