| 1 |
import { SchedulerLike, ValueFromArray } from '../types'; |
| 2 |
import { Observable } from '../Observable'; |
| 3 |
import { popScheduler } from '../util/args'; |
| 4 |
import { from } from './from'; |
| 5 |
|
| 6 |
// Devs are more likely to pass null or undefined than they are a scheduler |
| 7 |
// without accompanying values. To make things easier for (naughty) devs who |
| 8 |
// use the `strictNullChecks: false` TypeScript compiler option, these |
| 9 |
// overloads with explicit null and undefined values are included. |
| 10 |
|
| 11 |
export function of(value: null): Observable<null>; |
| 12 |
export function of(value: undefined): Observable<undefined>; |
| 13 |
|
| 14 |
/** @deprecated The `scheduler` parameter will be removed in v8. Use `scheduled`. Details: https://rxjs.dev/deprecations/scheduler-argument */ |
| 15 |
export function of(scheduler: SchedulerLike): Observable<never>; |
| 16 |
/** @deprecated The `scheduler` parameter will be removed in v8. Use `scheduled`. Details: https://rxjs.dev/deprecations/scheduler-argument */ |
| 17 |
export function of<A extends readonly unknown[]>(...valuesAndScheduler: [...A, SchedulerLike]): Observable<ValueFromArray<A>>; |
| 18 |
|
| 19 |
export function of(): Observable<never>; |
| 20 |
/** @deprecated Do not specify explicit type parameters. Signatures with type parameters that cannot be inferred will be removed in v8. */ |
| 21 |
export function of<T>(): Observable<T>; |
| 22 |
export function of<T>(value: T): Observable<T>; |
| 23 |
export function of<A extends readonly unknown[]>(...values: A): Observable<ValueFromArray<A>>; |
| 24 |
|
| 25 |
/** |
| 26 |
* Converts the arguments to an observable sequence. |
| 27 |
* |
| 28 |
* <span class="informal">Each argument becomes a `next` notification.</span> |
| 29 |
* |
| 30 |
*  |
| 31 |
* |
| 32 |
* Unlike {@link from}, it does not do any flattening and emits each argument in whole |
| 33 |
* as a separate `next` notification. |
| 34 |
* |
| 35 |
* ## Examples |
| 36 |
* |
| 37 |
* Emit the values `10, 20, 30` |
| 38 |
* |
| 39 |
* ```ts |
| 40 |
* import { of } from 'rxjs'; |
| 41 |
* |
| 42 |
* of(10, 20, 30) |
| 43 |
* .subscribe({ |
| 44 |
* next: value => console.log('next:', value), |
| 45 |
* error: err => console.log('error:', err), |
| 46 |
* complete: () => console.log('the end'), |
| 47 |
* }); |
| 48 |
* |
| 49 |
* // Outputs |
| 50 |
* // next: 10 |
| 51 |
* // next: 20 |
| 52 |
* // next: 30 |
| 53 |
* // the end |
| 54 |
* ``` |
| 55 |
* |
| 56 |
* Emit the array `[1, 2, 3]` |
| 57 |
* |
| 58 |
* ```ts |
| 59 |
* import { of } from 'rxjs'; |
| 60 |
* |
| 61 |
* of([1, 2, 3]) |
| 62 |
* .subscribe({ |
| 63 |
* next: value => console.log('next:', value), |
| 64 |
* error: err => console.log('error:', err), |
| 65 |
* complete: () => console.log('the end'), |
| 66 |
* }); |
| 67 |
* |
| 68 |
* // Outputs |
| 69 |
* // next: [1, 2, 3] |
| 70 |
* // the end |
| 71 |
* ``` |
| 72 |
* |
| 73 |
* @see {@link from} |
| 74 |
* @see {@link range} |
| 75 |
* |
| 76 |
* @param args A comma separated list of arguments you want to be emitted. |
| 77 |
* @return An Observable that synchronously emits the arguments described |
| 78 |
* above and then immediately completes. |
| 79 |
*/ |
| 80 |
export function of<T>(...args: Array<T | SchedulerLike>): Observable<T> { |
| 81 |
const scheduler = popScheduler(args); |
| 82 |
return from(args as T[], scheduler); |
| 83 |
} |