Front end of the Slack clone application.

switch.d.ts 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Observable } from '../Observable';
  2. /**
  3. * Converts a higher-order Observable into a first-order Observable by
  4. * subscribing to only the most recently emitted of those inner Observables.
  5. *
  6. * <span class="informal">Flattens an Observable-of-Observables by dropping the
  7. * previous inner Observable once a new one appears.</span>
  8. *
  9. * <img src="./img/switch.png" width="100%">
  10. *
  11. * `switch` subscribes to an Observable that emits Observables, also known as a
  12. * higher-order Observable. Each time it observes one of these emitted inner
  13. * Observables, the output Observable subscribes to the inner Observable and
  14. * begins emitting the items emitted by that. So far, it behaves
  15. * like {@link mergeAll}. However, when a new inner Observable is emitted,
  16. * `switch` unsubscribes from the earlier-emitted inner Observable and
  17. * subscribes to the new inner Observable and begins emitting items from it. It
  18. * continues to behave like this for subsequent inner Observables.
  19. *
  20. * @example <caption>Rerun an interval Observable on every click event</caption>
  21. * var clicks = Rx.Observable.fromEvent(document, 'click');
  22. * // Each click event is mapped to an Observable that ticks every second
  23. * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000));
  24. * var switched = higherOrder.switch();
  25. * // The outcome is that `switched` is essentially a timer that restarts
  26. * // on every click. The interval Observables from older clicks do not merge
  27. * // with the current interval Observable.
  28. * switched.subscribe(x => console.log(x));
  29. *
  30. * @see {@link combineAll}
  31. * @see {@link concatAll}
  32. * @see {@link exhaust}
  33. * @see {@link mergeAll}
  34. * @see {@link switchMap}
  35. * @see {@link switchMapTo}
  36. * @see {@link zipAll}
  37. *
  38. * @return {Observable<T>} An Observable that emits the items emitted by the
  39. * Observable most recently emitted by the source Observable.
  40. * @method switch
  41. * @name switch
  42. * @owner Observable
  43. */
  44. export declare function _switch<T>(this: Observable<Observable<T>>): Observable<T>;