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.

concatMap.ts 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { mergeMap } from './mergeMap';
  2. import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
  3. /* tslint:disable:max-line-length */
  4. export function concatMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O): OperatorFunction<T, ObservedValueOf<O>>;
  5. /** @deprecated resultSelector no longer supported, use inner map instead */
  6. export function concatMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: undefined): OperatorFunction<T, ObservedValueOf<O>>;
  7. /** @deprecated resultSelector no longer supported, use inner map instead */
  8. export function concatMap<T, R, O extends ObservableInput<any>>(project: (value: T, index: number) => 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 an Observable which is merged in the output
  12. * Observable, in a serialized fashion waiting for each one to complete before
  13. * merging the next.
  14. *
  15. * <span class="informal">Maps each value to an Observable, then flattens all of
  16. * these inner Observables using {@link concatAll}.</span>
  17. *
  18. * ![](concatMap.png)
  19. *
  20. * Returns an Observable that emits items based on applying a function that you
  21. * supply to each item emitted by the source Observable, where that function
  22. * returns an (so-called "inner") Observable. Each new inner Observable is
  23. * concatenated with the previous inner Observable.
  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: `concatMap` is equivalent to `mergeMap` with concurrency parameter set
  31. * to `1`.
  32. *
  33. * ## Example
  34. * For each click event, tick every second from 0 to 3, with no concurrency
  35. *
  36. * ```ts
  37. * import { fromEvent, interval } from 'rxjs';
  38. * import { concatMap, take } from 'rxjs/operators';
  39. *
  40. * const clicks = fromEvent(document, 'click');
  41. * const result = clicks.pipe(
  42. * concatMap(ev => interval(1000).pipe(take(4)))
  43. * );
  44. * result.subscribe(x => console.log(x));
  45. *
  46. * // Results in the following:
  47. * // (results are not concurrent)
  48. * // For every click on the "document" it will emit values 0 to 3 spaced
  49. * // on a 1000ms interval
  50. * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
  51. * ```
  52. *
  53. * @see {@link concat}
  54. * @see {@link concatAll}
  55. * @see {@link concatMapTo}
  56. * @see {@link exhaustMap}
  57. * @see {@link mergeMap}
  58. * @see {@link switchMap}
  59. *
  60. * @param {function(value: T, ?index: number): ObservableInput} project A function
  61. * that, when applied to an item emitted by the source Observable, returns an
  62. * Observable.
  63. * @return {Observable} An Observable that emits the result of applying the
  64. * projection function (and the optional deprecated `resultSelector`) to each item emitted
  65. * by the source Observable and taking values from each projected inner
  66. * Observable sequentially.
  67. * @method concatMap
  68. * @owner Observable
  69. */
  70. export function concatMap<T, R, O extends ObservableInput<any>>(
  71. project: (value: T, index: number) => O,
  72. resultSelector?: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
  73. ): OperatorFunction<T, ObservedValueOf<O>|R> {
  74. return mergeMap(project, resultSelector, 1);
  75. }