Observable.d.ts 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { PartialObserver } from './Observer';
  2. import { Operator } from './Operator';
  3. import { Subscriber } from './Subscriber';
  4. import { Subscription, AnonymousSubscription, TeardownLogic } from './Subscription';
  5. import { IfObservable } from './observable/IfObservable';
  6. import { ErrorObservable } from './observable/ErrorObservable';
  7. import { OperatorFunction } from './interfaces';
  8. export interface Subscribable<T> {
  9. subscribe(observerOrNext?: PartialObserver<T> | ((value: T) => void), error?: (error: any) => void, complete?: () => void): AnonymousSubscription;
  10. }
  11. export declare type SubscribableOrPromise<T> = Subscribable<T> | PromiseLike<T>;
  12. export declare type ObservableInput<T> = SubscribableOrPromise<T> | ArrayLike<T>;
  13. /**
  14. * A representation of any set of values over any amount of time. This is the most basic building block
  15. * of RxJS.
  16. *
  17. * @class Observable<T>
  18. */
  19. export declare class Observable<T> implements Subscribable<T> {
  20. _isScalar: boolean;
  21. /** @deprecated internal use only */ source: Observable<any>;
  22. protected operator: Operator<any, T>;
  23. /**
  24. * @constructor
  25. * @param {Function} subscribe the function that is called when the Observable is
  26. * initially subscribed to. This function is given a Subscriber, to which new values
  27. * can be `next`ed, or an `error` method can be called to raise an error, or
  28. * `complete` can be called to notify of a successful completion.
  29. */
  30. constructor(subscribe?: (this: Observable<T>, subscriber: Subscriber<T>) => TeardownLogic);
  31. /**
  32. * Creates a new cold Observable by calling the Observable constructor
  33. * @static true
  34. * @owner Observable
  35. * @method create
  36. * @param {Function} subscribe? the subscriber function to be passed to the Observable constructor
  37. * @return {Observable} a new cold observable
  38. */
  39. static create: Function;
  40. /**
  41. * Creates a new Observable, with this Observable as the source, and the passed
  42. * operator defined as the new observable's operator.
  43. * @method lift
  44. * @param {Operator} operator the operator defining the operation to take on the observable
  45. * @return {Observable} a new observable with the Operator applied
  46. */
  47. lift<R>(operator: Operator<T, R>): Observable<R>;
  48. subscribe(observer?: PartialObserver<T>): Subscription;
  49. subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
  50. protected _trySubscribe(sink: Subscriber<T>): TeardownLogic;
  51. /**
  52. * @method forEach
  53. * @param {Function} next a handler for each value emitted by the observable
  54. * @param {PromiseConstructor} [PromiseCtor] a constructor function used to instantiate the Promise
  55. * @return {Promise} a promise that either resolves on observable completion or
  56. * rejects with the handled error
  57. */
  58. forEach(next: (value: T) => void, PromiseCtor?: typeof Promise): Promise<void>;
  59. /** @deprecated internal use only */ _subscribe(subscriber: Subscriber<any>): TeardownLogic;
  60. static if: typeof IfObservable.create;
  61. static throw: typeof ErrorObservable.create;
  62. pipe(): Observable<T>;
  63. pipe<A>(op1: OperatorFunction<T, A>): Observable<A>;
  64. pipe<A, B>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>): Observable<B>;
  65. pipe<A, B, C>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>): Observable<C>;
  66. pipe<A, B, C, D>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>): Observable<D>;
  67. 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>;
  68. 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>;
  69. 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>;
  70. 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>;
  71. 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>;
  72. pipe<R>(...operations: OperatorFunction<T, R>[]): Observable<R>;
  73. toPromise<T>(this: Observable<T>): Promise<T>;
  74. toPromise<T>(this: Observable<T>, PromiseCtor: typeof Promise): Promise<T>;
  75. toPromise<T>(this: Observable<T>, PromiseCtor: PromiseConstructorLike): Promise<T>;
  76. }