cf725be63852f4d760914fa7c9e88198efcf0d4ed4293b86e55ee2bb968d1ca382718d63e5989f27d451c23e5411501c255ae0f931a3dd969a7e51433db108 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Observable } from '../Observable';
  2. import { ObservableInput, OperatorFunction } from '../types';
  3. /**
  4. * Branch out the source Observable values as a nested Observable using a
  5. * factory function of closing Observables to determine when to start a new
  6. * window.
  7. *
  8. * <span class="informal">It's like {@link bufferWhen}, but emits a nested
  9. * Observable instead of an array.</span>
  10. *
  11. * ![](windowWhen.png)
  12. *
  13. * Returns an Observable that emits windows of items it collects from the source
  14. * Observable. The output Observable emits connected, non-overlapping windows.
  15. * It emits the current window and opens a new one whenever the Observable
  16. * produced by the specified `closingSelector` function emits an item. The first
  17. * window is opened immediately when subscribing to the output Observable.
  18. *
  19. * ## Example
  20. *
  21. * Emit only the first two clicks events in every window of [1-5] random seconds
  22. *
  23. * ```ts
  24. * import { fromEvent, windowWhen, interval, map, take, mergeAll } from 'rxjs';
  25. *
  26. * const clicks = fromEvent(document, 'click');
  27. * const result = clicks.pipe(
  28. * windowWhen(() => interval(1000 + Math.random() * 4000)),
  29. * map(win => win.pipe(take(2))), // take at most 2 emissions from each window
  30. * mergeAll() // flatten the Observable-of-Observables
  31. * );
  32. * result.subscribe(x => console.log(x));
  33. * ```
  34. *
  35. * @see {@link window}
  36. * @see {@link windowCount}
  37. * @see {@link windowTime}
  38. * @see {@link windowToggle}
  39. * @see {@link bufferWhen}
  40. *
  41. * @param closingSelector A function that takes no arguments and returns an
  42. * {@link ObservableInput} (that gets converted to Observable) that signals
  43. * (on either `next` or `complete`) when to close the previous window and
  44. * start a new one.
  45. * @return A function that returns an Observable of windows, which in turn are
  46. * Observables.
  47. */
  48. export declare function windowWhen<T>(closingSelector: () => ObservableInput<any>): OperatorFunction<T, Observable<T>>;
  49. //# sourceMappingURL=windowWhen.d.ts.map