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

startWith.ts 4.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Observable } from '../Observable';
  2. import { concat } from '../observable/concat';
  3. import { isScheduler } from '../util/isScheduler';
  4. import { MonoTypeOperatorFunction, OperatorFunction, SchedulerLike } from '../types';
  5. /* tslint:disable:max-line-length */
  6. /** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */
  7. export function startWith<T>(scheduler: SchedulerLike): MonoTypeOperatorFunction<T>;
  8. /** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */
  9. export function startWith<T, D>(v1: D, scheduler: SchedulerLike): OperatorFunction<T, T | D>;
  10. /** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */
  11. export function startWith<T, D, E>(v1: D, v2: E, scheduler: SchedulerLike): OperatorFunction<T, T | D | E>;
  12. /** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */
  13. export function startWith<T, D, E, F>(v1: D, v2: E, v3: F, scheduler: SchedulerLike): OperatorFunction<T, T | D | E | F>;
  14. /** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */
  15. export function startWith<T, D, E, F, G>(v1: D, v2: E, v3: F, v4: G, scheduler: SchedulerLike): OperatorFunction<T, T | D | E | F | G>;
  16. /** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */
  17. export function startWith<T, D, E, F, G, H>(v1: D, v2: E, v3: F, v4: G, v5: H, scheduler: SchedulerLike): OperatorFunction<T, T | D | E | F | G | H>;
  18. /** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */
  19. export function startWith<T, D, E, F, G, H, I>(v1: D, v2: E, v3: F, v4: G, v5: H, v6: I, scheduler: SchedulerLike): OperatorFunction<T, T | D | E | F | G | H | I>;
  20. export function startWith<T, D>(v1: D): OperatorFunction<T, T | D>;
  21. export function startWith<T, D, E>(v1: D, v2: E): OperatorFunction<T, T | D | E>;
  22. export function startWith<T, D, E, F>(v1: D, v2: E, v3: F): OperatorFunction<T, T | D | E | F>;
  23. export function startWith<T, D, E, F, G>(v1: D, v2: E, v3: F, v4: G): OperatorFunction<T, T | D | E | F | G>;
  24. export function startWith<T, D, E, F, G, H>(v1: D, v2: E, v3: F, v4: G, v5: H): OperatorFunction<T, T | D | E | F | G | H>;
  25. export function startWith<T, D, E, F, G, H, I>(v1: D, v2: E, v3: F, v4: G, v5: H, v6: I): OperatorFunction<T, T | D | E | F | G | H | I>;
  26. export function startWith<T, D = T>(...array: D[]): OperatorFunction<T, T | D>;
  27. /** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */
  28. export function startWith<T, D = T>(...array: Array<D | SchedulerLike>): OperatorFunction<T, T | D>;
  29. /* tslint:enable:max-line-length */
  30. /**
  31. * Returns an Observable that emits the items you specify as arguments before it begins to emit
  32. * items emitted by the source Observable.
  33. *
  34. * <span class="informal">First emits its arguments in order, and then any
  35. * emissions from the source.</span>
  36. *
  37. * ![](startWith.png)
  38. *
  39. * ## Examples
  40. *
  41. * Start the chain of emissions with `"first"`, `"second"`
  42. *
  43. * ```ts
  44. * import { of } from 'rxjs';
  45. * import { startWith } from 'rxjs/operators';
  46. *
  47. * of("from source")
  48. * .pipe(startWith("first", "second"))
  49. * .subscribe(x => console.log(x));
  50. *
  51. * // results:
  52. * // "first"
  53. * // "second"
  54. * // "from source"
  55. * ```
  56. *
  57. * @param {...T} values - Items you want the modified Observable to emit first.
  58. * @param {SchedulerLike} [scheduler] - A {@link SchedulerLike} to use for scheduling
  59. * the emissions of the `next` notifications.
  60. * @return {Observable} An Observable that emits the items in the specified Iterable and then emits the items
  61. * emitted by the source Observable.
  62. * @method startWith
  63. * @owner Observable
  64. */
  65. export function startWith<T, D>(...array: Array<T | SchedulerLike>): OperatorFunction<T, T | D> {
  66. const scheduler = array[array.length - 1] as SchedulerLike;
  67. if (isScheduler(scheduler)) {
  68. // deprecated path
  69. array.pop();
  70. return (source: Observable<T>) => concat(array as T[], source, scheduler);
  71. } else {
  72. return (source: Observable<T>) => concat(array as T[], source);
  73. }
  74. }