index.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * @license Angular v19.2.13
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { ReactiveNode, ValueEqualityFn, SIGNAL, SignalNode } from '../../weak_ref.d-DWHPG08n.js';
  7. export { REACTIVE_NODE, Reactive, SIGNAL_NODE, SignalGetter, consumerAfterComputation, consumerBeforeComputation, consumerDestroy, consumerMarkDirty, consumerPollProducersForChange, createSignal, defaultEquals, getActiveConsumer, isInNotificationPhase, isReactive, producerAccessed, producerIncrementEpoch, producerMarkClean, producerNotifyConsumers, producerUpdateValueVersion, producerUpdatesAllowed, runPostSignalSetFn, setActiveConsumer, setAlternateWeakRefImpl, setPostSignalSetFn, signalSetFn, signalUpdateFn } from '../../weak_ref.d-DWHPG08n.js';
  8. /**
  9. * A computation, which derives a value from a declarative reactive expression.
  10. *
  11. * `Computed`s are both producers and consumers of reactivity.
  12. */
  13. interface ComputedNode<T> extends ReactiveNode {
  14. /**
  15. * Current value of the computation, or one of the sentinel values above (`UNSET`, `COMPUTING`,
  16. * `ERROR`).
  17. */
  18. value: T;
  19. /**
  20. * If `value` is `ERRORED`, the error caught from the last computation attempt which will
  21. * be re-thrown.
  22. */
  23. error: unknown;
  24. /**
  25. * The computation function which will produce a new value.
  26. */
  27. computation: () => T;
  28. equal: ValueEqualityFn<T>;
  29. }
  30. type ComputedGetter<T> = (() => T) & {
  31. [SIGNAL]: ComputedNode<T>;
  32. };
  33. /**
  34. * Create a computed signal which derives a reactive value from an expression.
  35. */
  36. declare function createComputed<T>(computation: () => T, equal?: ValueEqualityFn<T>): ComputedGetter<T>;
  37. type ComputationFn<S, D> = (source: S, previous?: {
  38. source: S;
  39. value: D;
  40. }) => D;
  41. interface LinkedSignalNode<S, D> extends ReactiveNode {
  42. /**
  43. * Value of the source signal that was used to derive the computed value.
  44. */
  45. sourceValue: S;
  46. /**
  47. * Current state value, or one of the sentinel values (`UNSET`, `COMPUTING`,
  48. * `ERROR`).
  49. */
  50. value: D;
  51. /**
  52. * If `value` is `ERRORED`, the error caught from the last computation attempt which will
  53. * be re-thrown.
  54. */
  55. error: unknown;
  56. /**
  57. * The source function represents reactive dependency based on which the linked state is reset.
  58. */
  59. source: () => S;
  60. /**
  61. * The computation function which will produce a new value based on the source and, optionally - previous values.
  62. */
  63. computation: ComputationFn<S, D>;
  64. equal: ValueEqualityFn<D>;
  65. }
  66. type LinkedSignalGetter<S, D> = (() => D) & {
  67. [SIGNAL]: LinkedSignalNode<S, D>;
  68. };
  69. declare function createLinkedSignal<S, D>(sourceFn: () => S, computationFn: ComputationFn<S, D>, equalityFn?: ValueEqualityFn<D>): LinkedSignalGetter<S, D>;
  70. declare function linkedSignalSetFn<S, D>(node: LinkedSignalNode<S, D>, newValue: D): void;
  71. declare function linkedSignalUpdateFn<S, D>(node: LinkedSignalNode<S, D>, updater: (value: D) => D): void;
  72. declare function setThrowInvalidWriteToSignalError(fn: <T>(node: SignalNode<T>) => never): void;
  73. /**
  74. * A cleanup function that can be optionally registered from the watch logic. If registered, the
  75. * cleanup logic runs before the next watch execution.
  76. */
  77. type WatchCleanupFn = () => void;
  78. /**
  79. * A callback passed to the watch function that makes it possible to register cleanup logic.
  80. */
  81. type WatchCleanupRegisterFn = (cleanupFn: WatchCleanupFn) => void;
  82. interface Watch {
  83. notify(): void;
  84. /**
  85. * Execute the reactive expression in the context of this `Watch` consumer.
  86. *
  87. * Should be called by the user scheduling algorithm when the provided
  88. * `schedule` hook is called by `Watch`.
  89. */
  90. run(): void;
  91. cleanup(): void;
  92. /**
  93. * Destroy the watcher:
  94. * - disconnect it from the reactive graph;
  95. * - mark it as destroyed so subsequent run and notify operations are noop.
  96. */
  97. destroy(): void;
  98. [SIGNAL]: WatchNode;
  99. }
  100. interface WatchNode extends ReactiveNode {
  101. hasRun: boolean;
  102. fn: ((onCleanup: WatchCleanupRegisterFn) => void) | null;
  103. schedule: ((watch: Watch) => void) | null;
  104. cleanupFn: WatchCleanupFn;
  105. ref: Watch;
  106. }
  107. declare function createWatch(fn: (onCleanup: WatchCleanupRegisterFn) => void, schedule: (watch: Watch) => void, allowSignalWrites: boolean): Watch;
  108. /**
  109. * Execute an arbitrary function in a non-reactive (non-tracking) context. The executed function
  110. * can, optionally, return a value.
  111. */
  112. declare function untracked<T>(nonReactiveReadsFn: () => T): T;
  113. export { ReactiveNode, SIGNAL, SignalNode, ValueEqualityFn, createComputed, createLinkedSignal, createWatch, linkedSignalSetFn, linkedSignalUpdateFn, setThrowInvalidWriteToSignalError, untracked };
  114. export type { ComputationFn, ComputedNode, LinkedSignalGetter, LinkedSignalNode, Watch, WatchCleanupFn, WatchCleanupRegisterFn };