de12c1fd61c61f8c49bd4c878e7759871c046da4a1619bd8a8a8ed6cf700cdcda4ddf82401e41ff2e7d5e7af3f3c9ea85a58bb2abd3a95b649d4d6118260ee 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import { PartialObserver, ObservableNotification, CompleteNotification, NextNotification, ErrorNotification } from './types';
  2. import { Observable } from './Observable';
  3. /**
  4. * @deprecated Use a string literal instead. `NotificationKind` will be replaced with a type alias in v8.
  5. * It will not be replaced with a const enum as those are not compatible with isolated modules.
  6. */
  7. export declare enum NotificationKind {
  8. NEXT = "N",
  9. ERROR = "E",
  10. COMPLETE = "C"
  11. }
  12. /**
  13. * Represents a push-based event or value that an {@link Observable} can emit.
  14. * This class is particularly useful for operators that manage notifications,
  15. * like {@link materialize}, {@link dematerialize}, {@link observeOn}, and
  16. * others. Besides wrapping the actual delivered value, it also annotates it
  17. * with metadata of, for instance, what type of push message it is (`next`,
  18. * `error`, or `complete`).
  19. *
  20. * @see {@link materialize}
  21. * @see {@link dematerialize}
  22. * @see {@link observeOn}
  23. * @deprecated It is NOT recommended to create instances of `Notification` directly.
  24. * Rather, try to create POJOs matching the signature outlined in {@link ObservableNotification}.
  25. * For example: `{ kind: 'N', value: 1 }`, `{ kind: 'E', error: new Error('bad') }`, or `{ kind: 'C' }`.
  26. * Will be removed in v8.
  27. */
  28. export declare class Notification<T> {
  29. readonly kind: 'N' | 'E' | 'C';
  30. readonly value?: T | undefined;
  31. readonly error?: any;
  32. /**
  33. * A value signifying that the notification will "next" if observed. In truth,
  34. * This is really synonymous with just checking `kind === "N"`.
  35. * @deprecated Will be removed in v8. Instead, just check to see if the value of `kind` is `"N"`.
  36. */
  37. readonly hasValue: boolean;
  38. /**
  39. * Creates a "Next" notification object.
  40. * @param kind Always `'N'`
  41. * @param value The value to notify with if observed.
  42. * @deprecated Internal implementation detail. Use {@link Notification#createNext createNext} instead.
  43. */
  44. constructor(kind: 'N', value?: T);
  45. /**
  46. * Creates an "Error" notification object.
  47. * @param kind Always `'E'`
  48. * @param value Always `undefined`
  49. * @param error The error to notify with if observed.
  50. * @deprecated Internal implementation detail. Use {@link Notification#createError createError} instead.
  51. */
  52. constructor(kind: 'E', value: undefined, error: any);
  53. /**
  54. * Creates a "completion" notification object.
  55. * @param kind Always `'C'`
  56. * @deprecated Internal implementation detail. Use {@link Notification#createComplete createComplete} instead.
  57. */
  58. constructor(kind: 'C');
  59. /**
  60. * Executes the appropriate handler on a passed `observer` given the `kind` of notification.
  61. * If the handler is missing it will do nothing. Even if the notification is an error, if
  62. * there is no error handler on the observer, an error will not be thrown, it will noop.
  63. * @param observer The observer to notify.
  64. */
  65. observe(observer: PartialObserver<T>): void;
  66. /**
  67. * Executes a notification on the appropriate handler from a list provided.
  68. * If a handler is missing for the kind of notification, nothing is called
  69. * and no error is thrown, it will be a noop.
  70. * @param next A next handler
  71. * @param error An error handler
  72. * @param complete A complete handler
  73. * @deprecated Replaced with {@link Notification#observe observe}. Will be removed in v8.
  74. */
  75. do(next: (value: T) => void, error: (err: any) => void, complete: () => void): void;
  76. /**
  77. * Executes a notification on the appropriate handler from a list provided.
  78. * If a handler is missing for the kind of notification, nothing is called
  79. * and no error is thrown, it will be a noop.
  80. * @param next A next handler
  81. * @param error An error handler
  82. * @deprecated Replaced with {@link Notification#observe observe}. Will be removed in v8.
  83. */
  84. do(next: (value: T) => void, error: (err: any) => void): void;
  85. /**
  86. * Executes the next handler if the Notification is of `kind` `"N"`. Otherwise
  87. * this will not error, and it will be a noop.
  88. * @param next The next handler
  89. * @deprecated Replaced with {@link Notification#observe observe}. Will be removed in v8.
  90. */
  91. do(next: (value: T) => void): void;
  92. /**
  93. * Executes a notification on the appropriate handler from a list provided.
  94. * If a handler is missing for the kind of notification, nothing is called
  95. * and no error is thrown, it will be a noop.
  96. * @param next A next handler
  97. * @param error An error handler
  98. * @param complete A complete handler
  99. * @deprecated Replaced with {@link Notification#observe observe}. Will be removed in v8.
  100. */
  101. accept(next: (value: T) => void, error: (err: any) => void, complete: () => void): void;
  102. /**
  103. * Executes a notification on the appropriate handler from a list provided.
  104. * If a handler is missing for the kind of notification, nothing is called
  105. * and no error is thrown, it will be a noop.
  106. * @param next A next handler
  107. * @param error An error handler
  108. * @deprecated Replaced with {@link Notification#observe observe}. Will be removed in v8.
  109. */
  110. accept(next: (value: T) => void, error: (err: any) => void): void;
  111. /**
  112. * Executes the next handler if the Notification is of `kind` `"N"`. Otherwise
  113. * this will not error, and it will be a noop.
  114. * @param next The next handler
  115. * @deprecated Replaced with {@link Notification#observe observe}. Will be removed in v8.
  116. */
  117. accept(next: (value: T) => void): void;
  118. /**
  119. * Executes the appropriate handler on a passed `observer` given the `kind` of notification.
  120. * If the handler is missing it will do nothing. Even if the notification is an error, if
  121. * there is no error handler on the observer, an error will not be thrown, it will noop.
  122. * @param observer The observer to notify.
  123. * @deprecated Replaced with {@link Notification#observe observe}. Will be removed in v8.
  124. */
  125. accept(observer: PartialObserver<T>): void;
  126. /**
  127. * Returns a simple Observable that just delivers the notification represented
  128. * by this Notification instance.
  129. *
  130. * @deprecated Will be removed in v8. To convert a `Notification` to an {@link Observable},
  131. * use {@link of} and {@link dematerialize}: `of(notification).pipe(dematerialize())`.
  132. */
  133. toObservable(): Observable<T>;
  134. private static completeNotification;
  135. /**
  136. * A shortcut to create a Notification instance of the type `next` from a
  137. * given value.
  138. * @param value The `next` value.
  139. * @return The "next" Notification representing the argument.
  140. * @deprecated It is NOT recommended to create instances of `Notification` directly.
  141. * Rather, try to create POJOs matching the signature outlined in {@link ObservableNotification}.
  142. * For example: `{ kind: 'N', value: 1 }`, `{ kind: 'E', error: new Error('bad') }`, or `{ kind: 'C' }`.
  143. * Will be removed in v8.
  144. */
  145. static createNext<T>(value: T): Notification<T> & NextNotification<T>;
  146. /**
  147. * A shortcut to create a Notification instance of the type `error` from a
  148. * given error.
  149. * @param err The `error` error.
  150. * @return The "error" Notification representing the argument.
  151. * @deprecated It is NOT recommended to create instances of `Notification` directly.
  152. * Rather, try to create POJOs matching the signature outlined in {@link ObservableNotification}.
  153. * For example: `{ kind: 'N', value: 1 }`, `{ kind: 'E', error: new Error('bad') }`, or `{ kind: 'C' }`.
  154. * Will be removed in v8.
  155. */
  156. static createError(err?: any): Notification<never> & ErrorNotification;
  157. /**
  158. * A shortcut to create a Notification instance of the type `complete`.
  159. * @return The valueless "complete" Notification.
  160. * @deprecated It is NOT recommended to create instances of `Notification` directly.
  161. * Rather, try to create POJOs matching the signature outlined in {@link ObservableNotification}.
  162. * For example: `{ kind: 'N', value: 1 }`, `{ kind: 'E', error: new Error('bad') }`, or `{ kind: 'C' }`.
  163. * Will be removed in v8.
  164. */
  165. static createComplete(): Notification<never> & CompleteNotification;
  166. }
  167. /**
  168. * Executes the appropriate handler on a passed `observer` given the `kind` of notification.
  169. * If the handler is missing it will do nothing. Even if the notification is an error, if
  170. * there is no error handler on the observer, an error will not be thrown, it will noop.
  171. * @param notification The notification object to observe.
  172. * @param observer The observer to notify.
  173. */
  174. export declare function observeNotification<T>(notification: ObservableNotification<T>, observer: PartialObserver<T>): void;
  175. //# sourceMappingURL=Notification.d.ts.map