Subscriber.d.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { Observer, PartialObserver } from './types';
  2. import { Subscription } from './Subscription';
  3. /**
  4. * Implements the {@link Observer} interface and extends the
  5. * {@link Subscription} class. While the {@link Observer} is the public API for
  6. * consuming the values of an {@link Observable}, all Observers get converted to
  7. * a Subscriber, in order to provide Subscription-like capabilities such as
  8. * `unsubscribe`. Subscriber is a common type in RxJS, and crucial for
  9. * implementing operators, but it is rarely used as a public API.
  10. *
  11. * @class Subscriber<T>
  12. */
  13. export declare class Subscriber<T> extends Subscription implements Observer<T> {
  14. /**
  15. * A static factory for a Subscriber, given a (potentially partial) definition
  16. * of an Observer.
  17. * @param {function(x: ?T): void} [next] The `next` callback of an Observer.
  18. * @param {function(e: ?any): void} [error] The `error` callback of an
  19. * Observer.
  20. * @param {function(): void} [complete] The `complete` callback of an
  21. * Observer.
  22. * @return {Subscriber<T>} A Subscriber wrapping the (partially defined)
  23. * Observer represented by the given arguments.
  24. * @nocollapse
  25. */
  26. static create<T>(next?: (x?: T) => void, error?: (e?: any) => void, complete?: () => void): Subscriber<T>;
  27. /** @internal */ syncErrorValue: any;
  28. /** @internal */ syncErrorThrown: boolean;
  29. /** @internal */ syncErrorThrowable: boolean;
  30. protected isStopped: boolean;
  31. protected destination: PartialObserver<any> | Subscriber<any>;
  32. /**
  33. * @param {Observer|function(value: T): void} [destinationOrNext] A partially
  34. * defined Observer or a `next` callback function.
  35. * @param {function(e: ?any): void} [error] The `error` callback of an
  36. * Observer.
  37. * @param {function(): void} [complete] The `complete` callback of an
  38. * Observer.
  39. */
  40. constructor(destinationOrNext?: PartialObserver<any> | ((value: T) => void), error?: (e?: any) => void, complete?: () => void);
  41. /**
  42. * The {@link Observer} callback to receive notifications of type `next` from
  43. * the Observable, with a value. The Observable may call this method 0 or more
  44. * times.
  45. * @param {T} [value] The `next` value.
  46. * @return {void}
  47. */
  48. next(value?: T): void;
  49. /**
  50. * The {@link Observer} callback to receive notifications of type `error` from
  51. * the Observable, with an attached `Error`. Notifies the Observer that
  52. * the Observable has experienced an error condition.
  53. * @param {any} [err] The `error` exception.
  54. * @return {void}
  55. */
  56. error(err?: any): void;
  57. /**
  58. * The {@link Observer} callback to receive a valueless notification of type
  59. * `complete` from the Observable. Notifies the Observer that the Observable
  60. * has finished sending push-based notifications.
  61. * @return {void}
  62. */
  63. complete(): void;
  64. unsubscribe(): void;
  65. protected _next(value: T): void;
  66. protected _error(err: any): void;
  67. protected _complete(): void;
  68. /** @deprecated This is an internal implementation detail, do not use. */
  69. _unsubscribeAndRecycle(): Subscriber<T>;
  70. }
  71. /**
  72. * We need this JSDoc comment for affecting ESDoc.
  73. * @ignore
  74. * @extends {Ignored}
  75. */
  76. export declare class SafeSubscriber<T> extends Subscriber<T> {
  77. private _parentSubscriber;
  78. private _context;
  79. constructor(_parentSubscriber: Subscriber<T>, observerOrNext?: PartialObserver<T> | ((value: T) => void), error?: (e?: any) => void, complete?: () => void);
  80. next(value?: T): void;
  81. error(err?: any): void;
  82. complete(): void;
  83. private __tryOrUnsub;
  84. private __tryOrSetError;
  85. /** @internal This is an internal implementation detail, do not use. */
  86. _unsubscribe(): void;
  87. }