merge.js 2.4KB

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