import { Observable } from '../Observable'; import { subscribeTo } from '../util/subscribeTo'; import { ObservableInput, SchedulerLike, ObservedValueOf } from '../types'; import { scheduled } from '../scheduled/scheduled'; export function from<O extends ObservableInput<any>>(input: O): Observable<ObservedValueOf<O>>; /** @deprecated use {@link scheduled} instead. */ export function from<O extends ObservableInput<any>>(input: O, scheduler: SchedulerLike): Observable<ObservedValueOf<O>>; /** * Creates an Observable from an Array, an array-like object, a Promise, an iterable object, or an Observable-like object. * * <span class="informal">Converts almost anything to an Observable.</span> * *  * * `from` converts various other objects and data types into Observables. It also converts a Promise, an array-like, or an * <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable" target="_blank">iterable</a> * object into an Observable that emits the items in that promise, array, or iterable. A String, in this context, is treated * as an array of characters. Observable-like objects (contains a function named with the ES2015 Symbol for Observable) can also be * converted through this operator. * * ## Examples * * ### Converts an array to an Observable * * ```ts * import { from } from 'rxjs'; * * const array = [10, 20, 30]; * const result = from(array); * * result.subscribe(x => console.log(x)); * * // Logs: * // 10 * // 20 * // 30 * ``` * * --- * * ### Convert an infinite iterable (from a generator) to an Observable * * ```ts * import { from } from 'rxjs'; * import { take } from 'rxjs/operators'; * * function* generateDoubles(seed) { * let i = seed; * while (true) { * yield i; * i = 2 * i; // double it * } * } * * const iterator = generateDoubles(3); * const result = from(iterator).pipe(take(10)); * * result.subscribe(x => console.log(x)); * * // Logs: * // 3 * // 6 * // 12 * // 24 * // 48 * // 96 * // 192 * // 384 * // 768 * // 1536 * ``` * * --- * * ### With async scheduler * * ```ts * import { from, asyncScheduler } from 'rxjs'; * * console.log('start'); * * const array = [10, 20, 30]; * const result = from(array, asyncScheduler); * * result.subscribe(x => console.log(x)); * * console.log('end'); * * // Logs: * // start * // end * // 10 * // 20 * // 30 * ``` * * @see {@link fromEvent} * @see {@link fromEventPattern} * * @param {ObservableInput<T>} A subscription object, a Promise, an Observable-like, * an Array, an iterable, or an array-like object to be converted. * @param {SchedulerLike} An optional {@link SchedulerLike} on which to schedule the emission of values. * @return {Observable<T>} * @name from * @owner Observable */ export function from<T>(input: ObservableInput<T>, scheduler?: SchedulerLike): Observable<T> { if (!scheduler) { if (input instanceof Observable) { return input; } return new Observable<T>(subscribeTo(input)); } else { return scheduled(input, scheduler); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
dom | Folder | 0755 |
|
|
ConnectableObservable.ts | File | 5.42 KB | 0644 |
|
SubscribeOnObservable.ts | File | 1.59 KB | 0644 |
|
bindCallback.ts | File | 15.9 KB | 0644 |
|
bindNodeCallback.ts | File | 15.41 KB | 0644 |
|
combineLatest.ts | File | 21.95 KB | 0644 |
|
concat.ts | File | 9.43 KB | 0644 |
|
defer.ts | File | 2.53 KB | 0644 |
|
empty.ts | File | 2.21 KB | 0644 |
|
forkJoin.ts | File | 9.49 KB | 0644 |
|
from.ts | File | 3.06 KB | 0644 |
|
fromArray.ts | File | 423 B | 0644 |
|
fromEvent.ts | File | 10.38 KB | 0644 |
|
fromEventPattern.ts | File | 7.14 KB | 0644 |
|
fromIterable.ts | File | 511 B | 0644 |
|
fromObservable.ts | File | 485 B | 0644 |
|
fromPromise.ts | File | 439 B | 0644 |
|
generate.ts | File | 12.55 KB | 0644 |
|
iif.ts | File | 3.22 KB | 0644 |
|
interval.ts | File | 2.53 KB | 0644 |
|
merge.ts | File | 9.94 KB | 0644 |
|
never.ts | File | 1.16 KB | 0644 |
|
of.ts | File | 4.77 KB | 0644 |
|
onErrorResumeNext.ts | File | 3.83 KB | 0644 |
|
pairs.ts | File | 3.06 KB | 0644 |
|
partition.ts | File | 2.61 KB | 0644 |
|
race.ts | File | 5.03 KB | 0644 |
|
range.ts | File | 2.28 KB | 0644 |
|
throwError.ts | File | 2.2 KB | 0644 |
|
timer.ts | File | 3.32 KB | 0644 |
|
using.ts | File | 3.04 KB | 0644 |
|
zip.ts | File | 12.06 KB | 0644 |
|