merge.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. var merge_1 = require('../observable/merge');
  3. var merge_2 = require('../observable/merge');
  4. exports.mergeStatic = merge_2.merge;
  5. /* tslint:enable:max-line-length */
  6. /**
  7. * Creates an output Observable which concurrently emits all values from every
  8. * given input Observable.
  9. *
  10. * <span class="informal">Flattens multiple Observables together by blending
  11. * their values into one Observable.</span>
  12. *
  13. * <img src="./img/merge.png" width="100%">
  14. *
  15. * `merge` subscribes to each given input Observable (either the source or an
  16. * Observable given as argument), and simply forwards (without doing any
  17. * transformation) all the values from all the input Observables to the output
  18. * Observable. The output Observable only completes once all input Observables
  19. * have completed. Any error delivered by an input Observable will be immediately
  20. * emitted on the output Observable.
  21. *
  22. * @example <caption>Merge together two Observables: 1s interval and clicks</caption>
  23. * var clicks = Rx.Observable.fromEvent(document, 'click');
  24. * var timer = Rx.Observable.interval(1000);
  25. * var clicksOrTimer = clicks.merge(timer);
  26. * clicksOrTimer.subscribe(x => console.log(x));
  27. *
  28. * @example <caption>Merge together 3 Observables, but only 2 run concurrently</caption>
  29. * var timer1 = Rx.Observable.interval(1000).take(10);
  30. * var timer2 = Rx.Observable.interval(2000).take(6);
  31. * var timer3 = Rx.Observable.interval(500).take(10);
  32. * var concurrent = 2; // the argument
  33. * var merged = timer1.merge(timer2, timer3, concurrent);
  34. * merged.subscribe(x => console.log(x));
  35. *
  36. * @see {@link mergeAll}
  37. * @see {@link mergeMap}
  38. * @see {@link mergeMapTo}
  39. * @see {@link mergeScan}
  40. *
  41. * @param {ObservableInput} other An input Observable to merge with the source
  42. * Observable. More than one input Observables may be given as argument.
  43. * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
  44. * Observables being subscribed to concurrently.
  45. * @param {Scheduler} [scheduler=null] The IScheduler to use for managing
  46. * concurrency of input Observables.
  47. * @return {Observable} An Observable that emits items that are the result of
  48. * every input Observable.
  49. * @method merge
  50. * @owner Observable
  51. */
  52. function merge() {
  53. var observables = [];
  54. for (var _i = 0; _i < arguments.length; _i++) {
  55. observables[_i - 0] = arguments[_i];
  56. }
  57. return function (source) { return source.lift.call(merge_1.merge.apply(void 0, [source].concat(observables))); };
  58. }
  59. exports.merge = merge;
  60. //# sourceMappingURL=merge.js.map