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