switchMapTo.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /* tslint:enable:max-line-length */
  5. /**
  6. * Projects each source value to the same Observable which is flattened multiple
  7. * times with {@link switch} in the output Observable.
  8. *
  9. * <span class="informal">It's like {@link switchMap}, but maps each value
  10. * always to the same inner Observable.</span>
  11. *
  12. * <img src="./img/switchMapTo.png" width="100%">
  13. *
  14. * Maps each source value to the given Observable `innerObservable` regardless
  15. * of the source value, and then flattens those resulting Observables into one
  16. * single Observable, which is the output Observable. The output Observables
  17. * emits values only from the most recently emitted instance of
  18. * `innerObservable`.
  19. *
  20. * @example <caption>Rerun an interval Observable on every click event</caption>
  21. * var clicks = Rx.Observable.fromEvent(document, 'click');
  22. * var result = clicks.switchMapTo(Rx.Observable.interval(1000));
  23. * result.subscribe(x => console.log(x));
  24. *
  25. * @see {@link concatMapTo}
  26. * @see {@link switch}
  27. * @see {@link switchMap}
  28. * @see {@link mergeMapTo}
  29. *
  30. * @param {ObservableInput} innerObservable An Observable to replace each value from
  31. * the source Observable.
  32. * @return {Observable} An Observable that emits items from the given
  33. * `innerObservable` (and optionally transformed through `resultSelector`) every
  34. * time a value is emitted on the source Observable, and taking only the values
  35. * from the most recently projected inner Observable.
  36. * @method switchMapTo
  37. * @owner Observable
  38. */
  39. function switchMapTo(innerObservable) {
  40. return operators_1.switchMapTo(innerObservable)(this);
  41. }
  42. exports.switchMapTo = switchMapTo;
  43. //# sourceMappingURL=switchMapTo.js.map