mergeMap.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Projects each source value to an Observable which is merged in the output
  6. * Observable.
  7. *
  8. * <span class="informal">Maps each value to an Observable, then flattens all of
  9. * these inner Observables using {@link mergeAll}.</span>
  10. *
  11. * <img src="./img/mergeMap.png" width="100%">
  12. *
  13. * Returns an Observable that emits items based on applying a function that you
  14. * supply to each item emitted by the source Observable, where that function
  15. * returns an Observable, and then merging those resulting Observables and
  16. * emitting the results of this merger.
  17. *
  18. * @example <caption>Map and flatten each letter to an Observable ticking every 1 second</caption>
  19. * var letters = Rx.Observable.of('a', 'b', 'c');
  20. * var result = letters.mergeMap(x =>
  21. * Rx.Observable.interval(1000).map(i => x+i)
  22. * );
  23. * result.subscribe(x => console.log(x));
  24. *
  25. * // Results in the following:
  26. * // a0
  27. * // b0
  28. * // c0
  29. * // a1
  30. * // b1
  31. * // c1
  32. * // continues to list a,b,c with respective ascending integers
  33. *
  34. * @see {@link concatMap}
  35. * @see {@link exhaustMap}
  36. * @see {@link merge}
  37. * @see {@link mergeAll}
  38. * @see {@link mergeMapTo}
  39. * @see {@link mergeScan}
  40. * @see {@link switchMap}
  41. *
  42. * @param {function(value: T, ?index: number): ObservableInput} project A function
  43. * that, when applied to an item emitted by the source Observable, returns an
  44. * Observable.
  45. * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
  46. * Observables being subscribed to concurrently.
  47. * @return {Observable} An Observable that emits the result of applying the
  48. * projection function (and the optional `resultSelector`) to each item emitted
  49. * by the source Observable and merging the results of the Observables obtained
  50. * from this transformation.
  51. * @method mergeMap
  52. * @owner Observable
  53. */
  54. function mergeMap(project, concurrent) {
  55. if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
  56. return operators_1.mergeMap(project, concurrent)(this);
  57. }
  58. exports.mergeMap = mergeMap;
  59. //# sourceMappingURL=mergeMap.js.map