concat.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { concat as concatStatic } from '../observable/concat';
  2. export { concat as concatStatic } from '../observable/concat';
  3. /* tslint:enable:max-line-length */
  4. /**
  5. * Creates an output Observable which sequentially emits all values from every
  6. * given input Observable after the current Observable.
  7. *
  8. * <span class="informal">Concatenates multiple Observables together by
  9. * sequentially emitting their values, one Observable after the other.</span>
  10. *
  11. * <img src="./img/concat.png" width="100%">
  12. *
  13. * Joins this Observable with multiple other Observables by subscribing to them
  14. * one at a time, starting with the source, and merging their results into the
  15. * output Observable. Will wait for each Observable to complete before moving
  16. * on to the next.
  17. *
  18. * @example <caption>Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10</caption>
  19. * var timer = Rx.Observable.interval(1000).take(4);
  20. * var sequence = Rx.Observable.range(1, 10);
  21. * var result = timer.concat(sequence);
  22. * result.subscribe(x => console.log(x));
  23. *
  24. * // results in:
  25. * // 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10
  26. *
  27. * @example <caption>Concatenate 3 Observables</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 result = timer1.concat(timer2, timer3);
  32. * result.subscribe(x => console.log(x));
  33. *
  34. * // results in the following:
  35. * // (Prints to console sequentially)
  36. * // -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9
  37. * // -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5
  38. * // -500ms-> 0 -500ms-> 1 -500ms-> ... 9
  39. *
  40. * @see {@link concatAll}
  41. * @see {@link concatMap}
  42. * @see {@link concatMapTo}
  43. *
  44. * @param {ObservableInput} other An input Observable to concatenate after the source
  45. * Observable. More than one input Observables may be given as argument.
  46. * @param {Scheduler} [scheduler=null] An optional IScheduler to schedule each
  47. * Observable subscription on.
  48. * @return {Observable} All values of each passed Observable merged into a
  49. * single Observable, in order, in serial fashion.
  50. * @method concat
  51. * @owner Observable
  52. */
  53. export function concat(...observables) {
  54. return (source) => source.lift.call(concatStatic(source, ...observables));
  55. }
  56. //# sourceMappingURL=concat.js.map