a zip code crypto-currency system good for red ONLY

switch.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { switchAll as higherOrder } from '../operators/switchAll';
  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 function _switch() {
  45. return higherOrder()(this);
  46. }
  47. //# sourceMappingURL=switch.js.map