Front end of the Slack clone application.

mergeMap.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /** PURE_IMPORTS_START .._operators_mergeMap PURE_IMPORTS_END */
  2. import { mergeMap as higherOrderMergeMap } from '../operators/mergeMap';
  3. /* tslint:enable:max-line-length */
  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 {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
  46. * A function to produce the value on the output Observable based on the values
  47. * and the indices of the source (outer) emission and the inner Observable
  48. * emission. The arguments passed to this function are:
  49. * - `outerValue`: the value that came from the source
  50. * - `innerValue`: the value that came from the projected Observable
  51. * - `outerIndex`: the "index" of the value that came from the source
  52. * - `innerIndex`: the "index" of the value from the projected Observable
  53. * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
  54. * Observables being subscribed to concurrently.
  55. * @return {Observable} An Observable that emits the result of applying the
  56. * projection function (and the optional `resultSelector`) to each item emitted
  57. * by the source Observable and merging the results of the Observables obtained
  58. * from this transformation.
  59. * @method mergeMap
  60. * @owner Observable
  61. */
  62. export function mergeMap(project, resultSelector, concurrent) {
  63. if (concurrent === void 0) {
  64. concurrent = Number.POSITIVE_INFINITY;
  65. }
  66. return higherOrderMergeMap(project, resultSelector, concurrent)(this);
  67. }
  68. //# sourceMappingURL=mergeMap.js.map