UNPKG

7.89 kBTypeScriptView Raw
1import { Operator } from './Operator';
2import { Subscriber } from './Subscriber';
3import { Subscription } from './Subscription';
4import { TeardownLogic, OperatorFunction, Subscribable, Observer } from './types';
5/**
6 * A representation of any set of values over any amount of time. This is the most basic building block
7 * of RxJS.
8 *
9 * @class Observable<T>
10 */
11export declare class Observable<T> implements Subscribable<T> {
12 /**
13 * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.
14 */
15 source: Observable<any> | undefined;
16 /**
17 * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.
18 */
19 operator: Operator<any, T> | undefined;
20 /**
21 * @constructor
22 * @param {Function} subscribe the function that is called when the Observable is
23 * initially subscribed to. This function is given a Subscriber, to which new values
24 * can be `next`ed, or an `error` method can be called to raise an error, or
25 * `complete` can be called to notify of a successful completion.
26 */
27 constructor(subscribe?: (this: Observable<T>, subscriber: Subscriber<T>) => TeardownLogic);
28 /**
29 * Creates a new Observable by calling the Observable constructor
30 * @owner Observable
31 * @method create
32 * @param {Function} subscribe? the subscriber function to be passed to the Observable constructor
33 * @return {Observable} a new observable
34 * @nocollapse
35 * @deprecated Use `new Observable()` instead. Will be removed in v8.
36 */
37 static create: (...args: any[]) => any;
38 /**
39 * Creates a new Observable, with this Observable instance as the source, and the passed
40 * operator defined as the new observable's operator.
41 * @method lift
42 * @param operator the operator defining the operation to take on the observable
43 * @return a new observable with the Operator applied
44 * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.
45 * If you have implemented an operator using `lift`, it is recommended that you create an
46 * operator by simply returning `new Observable()` directly. See "Creating new operators from
47 * scratch" section here: https://rxjs.dev/guide/operators
48 */
49 lift<R>(operator?: Operator<T, R>): Observable<R>;
50 subscribe(observerOrNext?: Partial<Observer<T>> | ((value: T) => void)): Subscription;
51 /** @deprecated Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments */
52 subscribe(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription;
53 /**
54 * Used as a NON-CANCELLABLE means of subscribing to an observable, for use with
55 * APIs that expect promises, like `async/await`. You cannot unsubscribe from this.
56 *
57 * **WARNING**: Only use this with observables you *know* will complete. If the source
58 * observable does not complete, you will end up with a promise that is hung up, and
59 * potentially all of the state of an async function hanging out in memory. To avoid
60 * this situation, look into adding something like {@link timeout}, {@link take},
61 * {@link takeWhile}, or {@link takeUntil} amongst others.
62 *
63 * #### Example
64 *
65 * ```ts
66 * import { interval, take } from 'rxjs';
67 *
68 * const source$ = interval(1000).pipe(take(4));
69 *
70 * async function getTotal() {
71 * let total = 0;
72 *
73 * await source$.forEach(value => {
74 * total += value;
75 * console.log('observable -> ' + value);
76 * });
77 *
78 * return total;
79 * }
80 *
81 * getTotal().then(
82 * total => console.log('Total: ' + total)
83 * );
84 *
85 * // Expected:
86 * // 'observable -> 0'
87 * // 'observable -> 1'
88 * // 'observable -> 2'
89 * // 'observable -> 3'
90 * // 'Total: 6'
91 * ```
92 *
93 * @param next a handler for each value emitted by the observable
94 * @return a promise that either resolves on observable completion or
95 * rejects with the handled error
96 */
97 forEach(next: (value: T) => void): Promise<void>;
98 /**
99 * @param next a handler for each value emitted by the observable
100 * @param promiseCtor a constructor function used to instantiate the Promise
101 * @return a promise that either resolves on observable completion or
102 * rejects with the handled error
103 * @deprecated Passing a Promise constructor will no longer be available
104 * in upcoming versions of RxJS. This is because it adds weight to the library, for very
105 * little benefit. If you need this functionality, it is recommended that you either
106 * polyfill Promise, or you create an adapter to convert the returned native promise
107 * to whatever promise implementation you wanted. Will be removed in v8.
108 */
109 forEach(next: (value: T) => void, promiseCtor: PromiseConstructorLike): Promise<void>;
110 pipe(): Observable<T>;
111 pipe<A>(op1: OperatorFunction<T, A>): Observable<A>;
112 pipe<A, B>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>): Observable<B>;
113 pipe<A, B, C>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>): Observable<C>;
114 pipe<A, B, C, D>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>): Observable<D>;
115 pipe<A, B, C, D, E>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>): Observable<E>;
116 pipe<A, B, C, D, E, F>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>): Observable<F>;
117 pipe<A, B, C, D, E, F, G>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>): Observable<G>;
118 pipe<A, B, C, D, E, F, G, H>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>): Observable<H>;
119 pipe<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>): Observable<I>;
120 pipe<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>, ...operations: OperatorFunction<any, any>[]): Observable<unknown>;
121 /** @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise */
122 toPromise(): Promise<T | undefined>;
123 /** @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise */
124 toPromise(PromiseCtor: typeof Promise): Promise<T | undefined>;
125 /** @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise */
126 toPromise(PromiseCtor: PromiseConstructorLike): Promise<T | undefined>;
127}
128//# sourceMappingURL=Observable.d.ts.map
\No newline at end of file