Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

mergeMapTo.ts 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Observable } from '../Observable';
  2. import { OperatorFunction, ObservedValueOf } from '../../internal/types';
  3. import { mergeMap } from './mergeMap';
  4. import { ObservableInput } from '../types';
  5. /* tslint:disable:max-line-length */
  6. export function mergeMapTo<T, O extends ObservableInput<any>>(innerObservable: O, concurrent?: number): OperatorFunction<any, ObservedValueOf<O>>;
  7. /** @deprecated */
  8. export function mergeMapTo<T, R, O extends ObservableInput<any>>(innerObservable: O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R, concurrent?: number): 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 the output Observable.
  13. *
  14. * <span class="informal">It's like {@link mergeMap}, but maps each value always
  15. * to the same inner Observable.</span>
  16. *
  17. * ![](mergeMapTo.png)
  18. *
  19. * Maps each source value to the given Observable `innerObservable` regardless
  20. * of the source value, and then merges those resulting Observables into one
  21. * single Observable, which is the output Observable.
  22. *
  23. * ## Example
  24. * For each click event, start an interval Observable ticking every 1 second
  25. * ```ts
  26. * import { fromEvent, interval } from 'rxjs';
  27. * import { mergeMapTo } from 'rxjs/operators';
  28. *
  29. * const clicks = fromEvent(document, 'click');
  30. * const result = clicks.pipe(mergeMapTo(interval(1000)));
  31. * result.subscribe(x => console.log(x));
  32. * ```
  33. *
  34. * @see {@link concatMapTo}
  35. * @see {@link merge}
  36. * @see {@link mergeAll}
  37. * @see {@link mergeMap}
  38. * @see {@link mergeScan}
  39. * @see {@link switchMapTo}
  40. *
  41. * @param {ObservableInput} innerObservable An Observable to replace each value from
  42. * the source Observable.
  43. * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
  44. * Observables being subscribed to concurrently.
  45. * @return {Observable} An Observable that emits items from the given
  46. * `innerObservable`
  47. * @method mergeMapTo
  48. * @owner Observable
  49. */
  50. export function mergeMapTo<T, R, O extends ObservableInput<any>>(
  51. innerObservable: O,
  52. resultSelector?: ((outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R) | number,
  53. concurrent: number = Number.POSITIVE_INFINITY
  54. ): OperatorFunction<T, ObservedValueOf<O>|R> {
  55. if (typeof resultSelector === 'function') {
  56. return mergeMap(() => innerObservable, resultSelector, concurrent);
  57. }
  58. if (typeof resultSelector === 'number') {
  59. concurrent = resultSelector;
  60. }
  61. return mergeMap(() => innerObservable, concurrent);
  62. }