windowToggle.d.ts 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { Observable } from '../Observable';
  2. /**
  3. * Branch out the source Observable values as a nested Observable starting from
  4. * an emission from `openings` and ending when the output of `closingSelector`
  5. * emits.
  6. *
  7. * <span class="informal">It's like {@link bufferToggle}, but emits a nested
  8. * Observable instead of an array.</span>
  9. *
  10. * <img src="./img/windowToggle.png" width="100%">
  11. *
  12. * Returns an Observable that emits windows of items it collects from the source
  13. * Observable. The output Observable emits windows that contain those items
  14. * emitted by the source Observable between the time when the `openings`
  15. * Observable emits an item and when the Observable returned by
  16. * `closingSelector` emits an item.
  17. *
  18. * @example <caption>Every other second, emit the click events from the next 500ms</caption>
  19. * var clicks = Rx.Observable.fromEvent(document, 'click');
  20. * var openings = Rx.Observable.interval(1000);
  21. * var result = clicks.windowToggle(openings, i =>
  22. * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty()
  23. * ).mergeAll();
  24. * result.subscribe(x => console.log(x));
  25. *
  26. * @see {@link window}
  27. * @see {@link windowCount}
  28. * @see {@link windowTime}
  29. * @see {@link windowWhen}
  30. * @see {@link bufferToggle}
  31. *
  32. * @param {Observable<O>} openings An observable of notifications to start new
  33. * windows.
  34. * @param {function(value: O): Observable} closingSelector A function that takes
  35. * the value emitted by the `openings` observable and returns an Observable,
  36. * which, when it emits (either `next` or `complete`), signals that the
  37. * associated window should complete.
  38. * @return {Observable<Observable<T>>} An observable of windows, which in turn
  39. * are Observables.
  40. * @method windowToggle
  41. * @owner Observable
  42. */
  43. export declare function windowToggle<T, O>(this: Observable<T>, openings: Observable<O>, closingSelector: (openValue: O) => Observable<any>): Observable<Observable<T>>;