windowTime.d.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Observable, SchedulerLike } from 'rxjs';
  2. /**
  3. * Branch out the source Observable values as a nested Observable periodically
  4. * in time.
  5. *
  6. * <span class="informal">It's like {@link bufferTime}, but emits a nested
  7. * Observable instead of an array.</span>
  8. *
  9. * <img src="./img/windowTime.png" width="100%">
  10. *
  11. * Returns an Observable that emits windows of items it collects from the source
  12. * Observable. The output Observable starts a new window periodically, as
  13. * determined by the `windowCreationInterval` argument. It emits each window
  14. * after a fixed timespan, specified by the `windowTimeSpan` argument. When the
  15. * source Observable completes or encounters an error, the output Observable
  16. * emits the current window and propagates the notification from the source
  17. * Observable. If `windowCreationInterval` is not provided, the output
  18. * Observable starts a new window when the previous window of duration
  19. * `windowTimeSpan` completes. If `maxWindowCount` is provided, each window
  20. * will emit at most fixed number of values. Window will complete immediately
  21. * after emitting last value and next one still will open as specified by
  22. * `windowTimeSpan` and `windowCreationInterval` arguments.
  23. *
  24. * @example <caption>In every window of 1 second each, emit at most 2 click events</caption>
  25. * var clicks = Rx.Observable.fromEvent(document, 'click');
  26. * var result = clicks.windowTime(1000)
  27. * .map(win => win.take(2)) // each window has at most 2 emissions
  28. * .mergeAll(); // flatten the Observable-of-Observables
  29. * result.subscribe(x => console.log(x));
  30. *
  31. * @example <caption>Every 5 seconds start a window 1 second long, and emit at most 2 click events per window</caption>
  32. * var clicks = Rx.Observable.fromEvent(document, 'click');
  33. * var result = clicks.windowTime(1000, 5000)
  34. * .map(win => win.take(2)) // each window has at most 2 emissions
  35. * .mergeAll(); // flatten the Observable-of-Observables
  36. * result.subscribe(x => console.log(x));
  37. *
  38. * @example <caption>Same as example above but with maxWindowCount instead of take</caption>
  39. * var clicks = Rx.Observable.fromEvent(document, 'click');
  40. * var result = clicks.windowTime(1000, 5000, 2) // each window has still at most 2 emissions
  41. * .mergeAll(); // flatten the Observable-of-Observables
  42. * result.subscribe(x => console.log(x));
  43. * @see {@link window}
  44. * @see {@link windowCount}
  45. * @see {@link windowToggle}
  46. * @see {@link windowWhen}
  47. * @see {@link bufferTime}
  48. *
  49. * @param {number} windowTimeSpan The amount of time to fill each window.
  50. * @param {number} [windowCreationInterval] The interval at which to start new
  51. * windows.
  52. * @param {number} [maxWindowSize=Number.POSITIVE_INFINITY] Max number of
  53. * values each window can emit before completion.
  54. * @param {Scheduler} [scheduler=async] The scheduler on which to schedule the
  55. * intervals that determine window boundaries.
  56. * @return {Observable<Observable<T>>} An observable of windows, which in turn
  57. * are Observables.
  58. * @method windowTime
  59. * @owner Observable
  60. */
  61. export declare function windowTime<T>(this: Observable<T>, windowTimeSpan: number, scheduler?: SchedulerLike): Observable<Observable<T>>;
  62. export declare function windowTime<T>(this: Observable<T>, windowTimeSpan: number, windowCreationInterval: number, scheduler?: SchedulerLike): Observable<Observable<T>>;
  63. export declare function windowTime<T>(this: Observable<T>, windowTimeSpan: number, windowCreationInterval: number, maxWindowSize: number, scheduler?: SchedulerLike): Observable<Observable<T>>;