concatMapTo.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Projects each source value to the same Observable which is merged multiple
  6. * times in a serialized fashion on the output Observable.
  7. *
  8. * <span class="informal">It's like {@link concatMap}, but maps each value
  9. * always to the same inner Observable.</span>
  10. *
  11. * <img src="./img/concatMapTo.png" width="100%">
  12. *
  13. * Maps each source value to the given Observable `innerObservable` regardless
  14. * of the source value, and then flattens those resulting Observables into one
  15. * single Observable, which is the output Observable. Each new `innerObservable`
  16. * instance emitted on the output Observable is concatenated with the previous
  17. * `innerObservable` instance.
  18. *
  19. * __Warning:__ if source values arrive endlessly and faster than their
  20. * corresponding inner Observables can complete, it will result in memory issues
  21. * as inner Observables amass in an unbounded buffer waiting for their turn to
  22. * be subscribed to.
  23. *
  24. * Note: `concatMapTo` is equivalent to `mergeMapTo` with concurrency parameter
  25. * set to `1`.
  26. *
  27. * @example <caption>For each click event, tick every second from 0 to 3, with no concurrency</caption>
  28. * var clicks = Rx.Observable.fromEvent(document, 'click');
  29. * var result = clicks.concatMapTo(Rx.Observable.interval(1000).take(4));
  30. * result.subscribe(x => console.log(x));
  31. *
  32. * // Results in the following:
  33. * // (results are not concurrent)
  34. * // For every click on the "document" it will emit values 0 to 3 spaced
  35. * // on a 1000ms interval
  36. * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
  37. *
  38. * @see {@link concat}
  39. * @see {@link concatAll}
  40. * @see {@link concatMap}
  41. * @see {@link mergeMapTo}
  42. * @see {@link switchMapTo}
  43. *
  44. * @param {ObservableInput} innerObservable An Observable to replace each value from
  45. * the source Observable.
  46. * @return {Observable} An observable of values merged together by joining the
  47. * passed observable with itself, one after the other, for each value emitted
  48. * from the source.
  49. * @method concatMapTo
  50. * @owner Observable
  51. */
  52. function concatMapTo(innerObservable) {
  53. return operators_1.concatMapTo(innerObservable)(this);
  54. }
  55. exports.concatMapTo = concatMapTo;
  56. //# sourceMappingURL=concatMapTo.js.map