index.d.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * @license Angular v16.2.9
  3. * (c) 2010-2022 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { DestroyRef } from '@angular/core';
  7. import { Injector } from '@angular/core';
  8. import { MonoTypeOperatorFunction } from 'rxjs';
  9. import { Observable } from 'rxjs';
  10. import { Signal } from '@angular/core';
  11. import { Subscribable } from 'rxjs';
  12. /**
  13. * Operator which completes the Observable when the calling context (component, directive, service,
  14. * etc) is destroyed.
  15. *
  16. * @param destroyRef optionally, the `DestroyRef` representing the current context. This can be
  17. * passed explicitly to use `takeUntilDestroyed` outside of an [injection
  18. * context](guide/dependency-injection-context). Otherwise, the current `DestroyRef` is injected.
  19. *
  20. * @developerPreview
  21. */
  22. export declare function takeUntilDestroyed<T>(destroyRef?: DestroyRef): MonoTypeOperatorFunction<T>;
  23. /**
  24. * Exposes the value of an Angular `Signal` as an RxJS `Observable`.
  25. *
  26. * The signal's value will be propagated into the `Observable`'s subscribers using an `effect`.
  27. *
  28. * `toObservable` must be called in an injection context unless an injector is provided via options.
  29. *
  30. * @developerPreview
  31. */
  32. export declare function toObservable<T>(source: Signal<T>, options?: ToObservableOptions): Observable<T>;
  33. /**
  34. * Options for `toObservable`.
  35. *
  36. * @developerPreview
  37. */
  38. export declare interface ToObservableOptions {
  39. /**
  40. * The `Injector` to use when creating the underlying `effect` which watches the signal.
  41. *
  42. * If this isn't specified, the current [injection context](guide/dependency-injection-context)
  43. * will be used.
  44. */
  45. injector?: Injector;
  46. }
  47. /**
  48. * Get the current value of an `Observable` as a reactive `Signal`.
  49. *
  50. * `toSignal` returns a `Signal` which provides synchronous reactive access to values produced
  51. * by the given `Observable`, by subscribing to that `Observable`. The returned `Signal` will always
  52. * have the most recent value emitted by the subscription, and will throw an error if the
  53. * `Observable` errors.
  54. *
  55. * Before the `Observable` emits its first value, the `Signal` will return `undefined`. To avoid
  56. * this, either an `initialValue` can be passed or the `requireSync` option enabled.
  57. *
  58. * By default, the subscription will be automatically cleaned up when the current [injection
  59. * context](guide/dependency-injection-context) is destroyed. For example, when `toObservable` is
  60. * called during the construction of a component, the subscription will be cleaned up when the
  61. * component is destroyed. If an [injection context](/guide/dependency-injection-context) is not
  62. * available, an explicit `Injector` can be passed instead.
  63. *
  64. * If the subscription should persist until the `Observable` itself completes, the `manualCleanup`
  65. * option can be specified instead, which disables the automatic subscription teardown. No injection
  66. * context is needed in this configuration as well.
  67. */
  68. export declare function toSignal<T>(source: Observable<T> | Subscribable<T>): Signal<T | undefined>;
  69. /**
  70. * Get the current value of an `Observable` as a reactive `Signal`.
  71. *
  72. * `toSignal` returns a `Signal` which provides synchronous reactive access to values produced
  73. * by the given `Observable`, by subscribing to that `Observable`. The returned `Signal` will always
  74. * have the most recent value emitted by the subscription, and will throw an error if the
  75. * `Observable` errors.
  76. *
  77. * Before the `Observable` emits its first value, the `Signal` will return the configured
  78. * `initialValue`, or `undefined` if no `initialValue` is provided. If the `Observable` is
  79. * guaranteed to emit synchronously, then the `requireSync` option can be passed instead.
  80. *
  81. * By default, the subscription will be automatically cleaned up when the current [injection
  82. * context](/guide/dependency-injection-context) is destroyed. For example, when `toObservable` is
  83. * called during the construction of a component, the subscription will be cleaned up when the
  84. * component is destroyed. If an injection context is not available, an explicit `Injector` can be
  85. * passed instead.
  86. *
  87. * If the subscription should persist until the `Observable` itself completes, the `manualCleanup`
  88. * option can be specified instead, which disables the automatic subscription teardown. No injection
  89. * context is needed in this configuration as well.
  90. *
  91. * @developerPreview
  92. */
  93. export declare function toSignal<T>(source: Observable<T> | Subscribable<T>, options?: ToSignalOptions<undefined> & {
  94. requireSync?: false;
  95. }): Signal<T | undefined>;
  96. /**
  97. * Get the current value of an `Observable` as a reactive `Signal`.
  98. *
  99. * `toSignal` returns a `Signal` which provides synchronous reactive access to values produced
  100. * by the given `Observable`, by subscribing to that `Observable`. The returned `Signal` will always
  101. * have the most recent value emitted by the subscription, and will throw an error if the
  102. * `Observable` errors.
  103. *
  104. * Before the `Observable` emits its first value, the `Signal` will return the configured
  105. * `initialValue`. If the `Observable` is guaranteed to emit synchronously, then the `requireSync`
  106. * option can be passed instead.
  107. *
  108. * By default, the subscription will be automatically cleaned up when the current [injection
  109. * context](guide/dependency-injection-context) is destroyed. For example, when `toObservable` is
  110. * called during the construction of a component, the subscription will be cleaned up when the
  111. * component is destroyed. If an [injection context](/guide/dependency-injection-context) is not
  112. * available, an explicit `Injector` can be passed instead.
  113. *
  114. * If the subscription should persist until the `Observable` itself completes, the `manualCleanup`
  115. * option can be specified instead, which disables the automatic subscription teardown. No injection
  116. * context is needed in this configuration as well.
  117. *
  118. * @developerPreview
  119. */
  120. export declare function toSignal<T, U extends T | null | undefined>(source: Observable<T> | Subscribable<T>, options: ToSignalOptions<U> & {
  121. initialValue: U;
  122. requireSync?: false;
  123. }): Signal<T | U>;
  124. /**
  125. * Get the current value of an `Observable` as a reactive `Signal`.
  126. *
  127. * `toSignal` returns a `Signal` which provides synchronous reactive access to values produced
  128. * by the given `Observable`, by subscribing to that `Observable`. The returned `Signal` will always
  129. * have the most recent value emitted by the subscription, and will throw an error if the
  130. * `Observable` errors.
  131. *
  132. * With `requireSync` set to `true`, `toSignal` will assert that the `Observable` produces a value
  133. * immediately upon subscription. No `initialValue` is needed in this case, and the returned signal
  134. * does not include an `undefined` type.
  135. *
  136. * By default, the subscription will be automatically cleaned up when the current [injection
  137. * context](/guide/dependency-injection-context) is destroyed. For example, when `toObservable` is
  138. * called during the construction of a component, the subscription will be cleaned up when the
  139. * component is destroyed. If an injection context is not available, an explicit `Injector` can be
  140. * passed instead.
  141. *
  142. * If the subscription should persist until the `Observable` itself completes, the `manualCleanup`
  143. * option can be specified instead, which disables the automatic subscription teardown. No injection
  144. * context is needed in this configuration as well.
  145. *
  146. * @developerPreview
  147. */
  148. export declare function toSignal<T>(source: Observable<T> | Subscribable<T>, options: ToSignalOptions<undefined> & {
  149. requireSync: true;
  150. }): Signal<T>;
  151. /**
  152. * Options for `toSignal`.
  153. *
  154. * @publicApi
  155. */
  156. export declare interface ToSignalOptions<T> {
  157. /**
  158. * Initial value for the signal produced by `toSignal`.
  159. *
  160. * This will be the value of the signal until the observable emits its first value.
  161. */
  162. initialValue?: T;
  163. /**
  164. * Whether to require that the observable emits synchronously when `toSignal` subscribes.
  165. *
  166. * If this is `true`, `toSignal` will assert that the observable produces a value immediately upon
  167. * subscription. Setting this option removes the need to either deal with `undefined` in the
  168. * signal type or provide an `initialValue`, at the cost of a runtime error if this requirement is
  169. * not met.
  170. */
  171. requireSync?: boolean;
  172. /**
  173. * `Injector` which will provide the `DestroyRef` used to clean up the Observable subscription.
  174. *
  175. * If this is not provided, a `DestroyRef` will be retrieved from the current [injection
  176. * context](/guide/dependency-injection-context), unless manual cleanup is requested.
  177. */
  178. injector?: Injector;
  179. /**
  180. * Whether the subscription should be automatically cleaned up (via `DestroyRef`) when
  181. * `toObservable`'s creation context is destroyed.
  182. *
  183. * If manual cleanup is enabled, then `DestroyRef` is not used, and the subscription will persist
  184. * until the `Observable` itself completes.
  185. */
  186. manualCleanup?: boolean;
  187. }
  188. export { }