Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

concatMapTo.ts 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { concatMap } from './concatMap';
  2. import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
  3. /* tslint:disable:max-line-length */
  4. export function concatMapTo<T, O extends ObservableInput<any>>(observable: O): OperatorFunction<T, ObservedValueOf<O>>;
  5. /** @deprecated */
  6. export function concatMapTo<T, O extends ObservableInput<any>>(observable: O, resultSelector: undefined): OperatorFunction<T, ObservedValueOf<O>>;
  7. /** @deprecated */
  8. export function concatMapTo<T, R, O extends ObservableInput<any>>(observable: O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;
  9. /* tslint:enable:max-line-length */
  10. /**
  11. * Projects each source value to the same Observable which is merged multiple
  12. * times in a serialized fashion on the output Observable.
  13. *
  14. * <span class="informal">It's like {@link concatMap}, but maps each value
  15. * always to the same inner Observable.</span>
  16. *
  17. * ![](concatMapTo.png)
  18. *
  19. * Maps each source value to the given Observable `innerObservable` regardless
  20. * of the source value, and then flattens those resulting Observables into one
  21. * single Observable, which is the output Observable. Each new `innerObservable`
  22. * instance emitted on the output Observable is concatenated with the previous
  23. * `innerObservable` instance.
  24. *
  25. * __Warning:__ if source values arrive endlessly and faster than their
  26. * corresponding inner Observables can complete, it will result in memory issues
  27. * as inner Observables amass in an unbounded buffer waiting for their turn to
  28. * be subscribed to.
  29. *
  30. * Note: `concatMapTo` is equivalent to `mergeMapTo` with concurrency parameter
  31. * set to `1`.
  32. *
  33. * ## Example
  34. * For each click event, tick every second from 0 to 3, with no concurrency
  35. * ```ts
  36. * import { fromEvent, interval } from 'rxjs';
  37. * import { concatMapTo, take } from 'rxjs/operators';
  38. *
  39. * const clicks = fromEvent(document, 'click');
  40. * const result = clicks.pipe(
  41. * concatMapTo(interval(1000).pipe(take(4))),
  42. * );
  43. * result.subscribe(x => console.log(x));
  44. *
  45. * // Results in the following:
  46. * // (results are not concurrent)
  47. * // For every click on the "document" it will emit values 0 to 3 spaced
  48. * // on a 1000ms interval
  49. * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
  50. * ```
  51. *
  52. * @see {@link concat}
  53. * @see {@link concatAll}
  54. * @see {@link concatMap}
  55. * @see {@link mergeMapTo}
  56. * @see {@link switchMapTo}
  57. *
  58. * @param {ObservableInput} innerObservable An Observable to replace each value from
  59. * the source Observable.
  60. * @return {Observable} An observable of values merged together by joining the
  61. * passed observable with itself, one after the other, for each value emitted
  62. * from the source.
  63. * @method concatMapTo
  64. * @owner Observable
  65. */
  66. export function concatMapTo<T, R, O extends ObservableInput<any>>(
  67. innerObservable: O,
  68. resultSelector?: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
  69. ): OperatorFunction<T, ObservedValueOf<O>|R> {
  70. return concatMap(() => innerObservable, resultSelector);
  71. }