@zeix/cause-effect 0.17.2 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/.ai-context.md +163 -226
  2. package/.cursorrules +41 -35
  3. package/.github/copilot-instructions.md +166 -116
  4. package/.zed/settings.json +3 -0
  5. package/ARCHITECTURE.md +274 -0
  6. package/CLAUDE.md +197 -202
  7. package/COLLECTION_REFACTORING.md +161 -0
  8. package/GUIDE.md +298 -0
  9. package/README.md +241 -220
  10. package/REQUIREMENTS.md +100 -0
  11. package/bench/reactivity.bench.ts +577 -0
  12. package/index.dev.js +1326 -1174
  13. package/index.js +1 -1
  14. package/index.ts +58 -85
  15. package/package.json +9 -6
  16. package/src/errors.ts +118 -70
  17. package/src/graph.ts +601 -0
  18. package/src/nodes/collection.ts +474 -0
  19. package/src/nodes/effect.ts +149 -0
  20. package/src/nodes/list.ts +588 -0
  21. package/src/nodes/memo.ts +120 -0
  22. package/src/nodes/sensor.ts +139 -0
  23. package/src/nodes/state.ts +135 -0
  24. package/src/nodes/store.ts +383 -0
  25. package/src/nodes/task.ts +146 -0
  26. package/src/signal.ts +112 -64
  27. package/src/util.ts +26 -57
  28. package/test/batch.test.ts +96 -69
  29. package/test/benchmark.test.ts +473 -485
  30. package/test/collection.test.ts +455 -955
  31. package/test/effect.test.ts +293 -696
  32. package/test/list.test.ts +332 -857
  33. package/test/memo.test.ts +380 -0
  34. package/test/regression.test.ts +156 -0
  35. package/test/scope.test.ts +191 -0
  36. package/test/sensor.test.ts +454 -0
  37. package/test/signal.test.ts +220 -213
  38. package/test/state.test.ts +217 -271
  39. package/test/store.test.ts +346 -898
  40. package/test/task.test.ts +395 -0
  41. package/test/untrack.test.ts +167 -0
  42. package/test/util/dependency-graph.ts +2 -2
  43. package/tsconfig.build.json +11 -0
  44. package/tsconfig.json +5 -7
  45. package/types/index.d.ts +13 -15
  46. package/types/src/errors.d.ts +73 -19
  47. package/types/src/graph.d.ts +208 -0
  48. package/types/src/nodes/collection.d.ts +64 -0
  49. package/types/src/nodes/effect.d.ts +48 -0
  50. package/types/src/nodes/list.d.ts +65 -0
  51. package/types/src/nodes/memo.d.ts +57 -0
  52. package/types/src/nodes/sensor.d.ts +75 -0
  53. package/types/src/nodes/state.d.ts +78 -0
  54. package/types/src/nodes/store.d.ts +51 -0
  55. package/types/src/nodes/task.d.ts +73 -0
  56. package/types/src/signal.d.ts +43 -28
  57. package/types/src/util.d.ts +9 -16
  58. package/archive/benchmark.ts +0 -688
  59. package/archive/collection.ts +0 -310
  60. package/archive/computed.ts +0 -198
  61. package/archive/list.ts +0 -544
  62. package/archive/memo.ts +0 -140
  63. package/archive/state.ts +0 -90
  64. package/archive/store.ts +0 -357
  65. package/archive/task.ts +0 -191
  66. package/src/classes/collection.ts +0 -298
  67. package/src/classes/composite.ts +0 -171
  68. package/src/classes/computed.ts +0 -392
  69. package/src/classes/list.ts +0 -310
  70. package/src/classes/ref.ts +0 -96
  71. package/src/classes/state.ts +0 -131
  72. package/src/classes/store.ts +0 -227
  73. package/src/diff.ts +0 -138
  74. package/src/effect.ts +0 -96
  75. package/src/match.ts +0 -45
  76. package/src/resolve.ts +0 -49
  77. package/src/system.ts +0 -275
  78. package/test/computed.test.ts +0 -1126
  79. package/test/diff.test.ts +0 -955
  80. package/test/match.test.ts +0 -388
  81. package/test/ref.test.ts +0 -381
  82. package/test/resolve.test.ts +0 -154
  83. package/types/src/classes/collection.d.ts +0 -47
  84. package/types/src/classes/composite.d.ts +0 -15
  85. package/types/src/classes/computed.d.ts +0 -114
  86. package/types/src/classes/list.d.ts +0 -41
  87. package/types/src/classes/ref.d.ts +0 -48
  88. package/types/src/classes/state.d.ts +0 -61
  89. package/types/src/classes/store.d.ts +0 -51
  90. package/types/src/diff.d.ts +0 -28
  91. package/types/src/effect.d.ts +0 -15
  92. package/types/src/match.d.ts +0 -21
  93. package/types/src/resolve.d.ts +0 -29
  94. package/types/src/system.d.ts +0 -81
@@ -1,114 +0,0 @@
1
- import { type Cleanup, type HookCallback, type WatchHook } from '../system';
2
- type Computed<T extends {}> = {
3
- readonly [Symbol.toStringTag]: 'Computed';
4
- get(): T;
5
- };
6
- type MemoCallback<T extends {} & {
7
- then?: undefined;
8
- }> = (oldValue: T) => T;
9
- type TaskCallback<T extends {} & {
10
- then?: undefined;
11
- }> = (oldValue: T, abort: AbortSignal) => Promise<T>;
12
- declare const TYPE_COMPUTED: "Computed";
13
- /**
14
- * Create a new memoized signal for a synchronous function.
15
- *
16
- * @since 0.17.0
17
- */
18
- declare class Memo<T extends {}> {
19
- #private;
20
- /**
21
- * Create a new memoized signal.
22
- *
23
- * @param {MemoCallback<T>} callback - Callback function to compute the memoized value
24
- * @param {T} [initialValue = UNSET] - Initial value of the signal
25
- * @throws {InvalidCallbackError} If the callback is not an sync function
26
- * @throws {InvalidSignalValueError} If the initial value is not valid
27
- */
28
- constructor(callback: MemoCallback<T>, initialValue?: T);
29
- get [Symbol.toStringTag](): 'Computed';
30
- /**
31
- * Return the memoized value after computing it if necessary.
32
- *
33
- * @returns {T}
34
- * @throws {CircularDependencyError} If a circular dependency is detected
35
- * @throws {Error} If an error occurs during computation
36
- */
37
- get(): T;
38
- /**
39
- * Register a callback to be called when HOOK_WATCH is triggered.
40
- *
41
- * @param {WatchHook} type - The type of hook to register the callback for; only HOOK_WATCH is supported
42
- * @param {HookCallback} callback - The callback to register
43
- * @returns {Cleanup} - A function to unregister the callback
44
- */
45
- on(type: WatchHook, callback: HookCallback): Cleanup;
46
- }
47
- /**
48
- * Create a new task signals that memoizes the result of an asynchronous function.
49
- *
50
- * @since 0.17.0
51
- */
52
- declare class Task<T extends {}> {
53
- #private;
54
- /**
55
- * Create a new task signal for an asynchronous function.
56
- *
57
- * @param {TaskCallback<T>} callback - The asynchronous function to compute the memoized value
58
- * @param {T} [initialValue = UNSET] - Initial value of the signal
59
- * @throws {InvalidCallbackError} If the callback is not an async function
60
- * @throws {InvalidSignalValueError} If the initial value is not valid
61
- */
62
- constructor(callback: TaskCallback<T>, initialValue?: T);
63
- get [Symbol.toStringTag](): 'Computed';
64
- /**
65
- * Return the memoized value after executing the async function if necessary.
66
- *
67
- * @returns {T}
68
- * @throws {CircularDependencyError} If a circular dependency is detected
69
- * @throws {Error} If an error occurs during computation
70
- */
71
- get(): T;
72
- /**
73
- * Register a callback to be called when HOOK_WATCH is triggered.
74
- *
75
- * @param {WatchHook} type - The type of hook to register the callback for; only HOOK_WATCH is supported
76
- * @param {HookCallback} callback - The callback to register
77
- * @returns {Cleanup} - A function to unregister the callback
78
- */
79
- on(type: WatchHook, callback: HookCallback): Cleanup;
80
- }
81
- /**
82
- * Create a derived signal from existing signals
83
- *
84
- * @since 0.9.0
85
- * @param {MemoCallback<T> | TaskCallback<T>} callback - Computation callback function
86
- */
87
- declare const createComputed: <T extends {}>(callback: TaskCallback<T> | MemoCallback<T>, initialValue?: T) => Task<T> | Memo<T>;
88
- /**
89
- * Check if a value is a computed signal
90
- *
91
- * @since 0.9.0
92
- * @param {unknown} value - Value to check
93
- * @returns {boolean} - True if value is a computed signal, false otherwise
94
- */
95
- declare const isComputed: <T extends {}>(value: unknown) => value is Memo<T>;
96
- /**
97
- * Check if the provided value is a callback that may be used as input for createSignal() to derive a computed state
98
- *
99
- * @since 0.12.0
100
- * @param {unknown} value - Value to check
101
- * @returns {boolean} - True if value is a sync callback, false otherwise
102
- */
103
- declare const isMemoCallback: <T extends {} & {
104
- then?: undefined;
105
- }>(value: unknown) => value is MemoCallback<T>;
106
- /**
107
- * Check if the provided value is a callback that may be used as input for createSignal() to derive a computed state
108
- *
109
- * @since 0.17.0
110
- * @param {unknown} value - Value to check
111
- * @returns {boolean} - True if value is an async callback, false otherwise
112
- */
113
- declare const isTaskCallback: <T extends {}>(value: unknown) => value is TaskCallback<T>;
114
- export { TYPE_COMPUTED, createComputed, isComputed, isMemoCallback, isTaskCallback, Memo, Task, type Computed, type MemoCallback, type TaskCallback, };
@@ -1,41 +0,0 @@
1
- import { type UnknownArray } from '../diff';
2
- import { type Cleanup, type Hook, type HookCallback } from '../system';
3
- import { DerivedCollection } from './collection';
4
- import { State } from './state';
5
- type ArrayToRecord<T extends UnknownArray> = {
6
- [key: string]: T extends Array<infer U extends {}> ? U : never;
7
- };
8
- type KeyConfig<T> = string | ((item: T) => string);
9
- declare const TYPE_LIST: "List";
10
- declare class List<T extends {}> {
11
- #private;
12
- constructor(initialValue: T[], keyConfig?: KeyConfig<T>);
13
- get [Symbol.toStringTag](): 'List';
14
- get [Symbol.isConcatSpreadable](): true;
15
- [Symbol.iterator](): IterableIterator<State<T>>;
16
- get length(): number;
17
- get(): T[];
18
- set(newValue: T[]): void;
19
- update(fn: (oldValue: T[]) => T[]): void;
20
- at(index: number): State<T> | undefined;
21
- keys(): IterableIterator<string>;
22
- byKey(key: string): State<T> | undefined;
23
- keyAt(index: number): string | undefined;
24
- indexOfKey(key: string): number;
25
- add(value: T): string;
26
- remove(keyOrIndex: string | number): void;
27
- sort(compareFn?: (a: T, b: T) => number): void;
28
- splice(start: number, deleteCount?: number, ...items: T[]): T[];
29
- on(type: Hook, callback: HookCallback): Cleanup;
30
- deriveCollection<R extends {}>(callback: (sourceValue: T) => R): DerivedCollection<R, T>;
31
- deriveCollection<R extends {}>(callback: (sourceValue: T, abort: AbortSignal) => Promise<R>): DerivedCollection<R, T>;
32
- }
33
- /**
34
- * Check if the provided value is a List instance
35
- *
36
- * @since 0.15.0
37
- * @param {unknown} value - Value to check
38
- * @returns {boolean} - True if the value is a List instance, false otherwise
39
- */
40
- declare const isList: <T extends {}>(value: unknown) => value is List<T>;
41
- export { isList, List, TYPE_LIST, type ArrayToRecord, type KeyConfig };
@@ -1,48 +0,0 @@
1
- import { type Guard } from '../errors';
2
- import { type Cleanup, type HookCallback, type WatchHook } from '../system';
3
- declare const TYPE_REF = "Ref";
4
- /**
5
- * Create a new ref signal.
6
- *
7
- * @since 0.17.1
8
- */
9
- declare class Ref<T extends {}> {
10
- #private;
11
- /**
12
- * Create a new ref signal.
13
- *
14
- * @param {T} value - Reference to external object
15
- * @param {Guard<T>} guard - Optional guard function to validate the value
16
- * @throws {NullishSignalValueError} - If the value is null or undefined
17
- * @throws {InvalidSignalValueError} - If the value is invalid
18
- */
19
- constructor(value: T, guard?: Guard<T>);
20
- get [Symbol.toStringTag](): string;
21
- /**
22
- * Get the value of the ref signal.
23
- *
24
- * @returns {T} - Object reference
25
- */
26
- get(): T;
27
- /**
28
- * Notify watchers of relevant changes in the external reference.
29
- */
30
- notify(): void;
31
- /**
32
- * Register a callback to be called when HOOK_WATCH is triggered.
33
- *
34
- * @param {WatchHook} type - The type of hook to register the callback for; only HOOK_WATCH is supported
35
- * @param {HookCallback} callback - The callback to register
36
- * @returns {Cleanup} - A function to unregister the callback
37
- */
38
- on(type: WatchHook, callback: HookCallback): Cleanup;
39
- }
40
- /**
41
- * Check if the provided value is a Ref instance
42
- *
43
- * @since 0.17.1
44
- * @param {unknown} value - Value to check
45
- * @returns {boolean} - True if the value is a Ref instance, false otherwise
46
- */
47
- declare const isRef: <T extends {}>(value: unknown) => value is Ref<T>;
48
- export { TYPE_REF, Ref, isRef };
@@ -1,61 +0,0 @@
1
- import { type Cleanup, type HookCallback, type WatchHook } from '../system';
2
- declare const TYPE_STATE: "State";
3
- /**
4
- * Create a new state signal.
5
- *
6
- * @since 0.17.0
7
- */
8
- declare class State<T extends {}> {
9
- #private;
10
- /**
11
- * Create a new state signal.
12
- *
13
- * @param {T} initialValue - Initial value of the state
14
- * @throws {NullishSignalValueError} - If the initial value is null or undefined
15
- * @throws {InvalidSignalValueError} - If the initial value is invalid
16
- */
17
- constructor(initialValue: T);
18
- get [Symbol.toStringTag](): string;
19
- /**
20
- * Get the current value of the state signal.
21
- *
22
- * @returns {T} - Current value of the state
23
- */
24
- get(): T;
25
- /**
26
- * Set the value of the state signal.
27
- *
28
- * @param {T} newValue - New value of the state
29
- * @returns {void}
30
- * @throws {NullishSignalValueError} - If the initial value is null or undefined
31
- * @throws {InvalidSignalValueError} - If the initial value is invalid
32
- */
33
- set(newValue: T): void;
34
- /**
35
- * Update the value of the state signal.
36
- *
37
- * @param {Function} updater - Function that takes the current value and returns the new value
38
- * @returns {void}
39
- * @throws {InvalidCallbackError} - If the updater function is not a function
40
- * @throws {NullishSignalValueError} - If the initial value is null or undefined
41
- * @throws {InvalidSignalValueError} - If the initial value is invalid
42
- */
43
- update(updater: (oldValue: T) => T): void;
44
- /**
45
- * Register a callback to be called when HOOK_WATCH is triggered.
46
- *
47
- * @param {WatchHook} type - The type of hook to register the callback for; only HOOK_WATCH is supported
48
- * @param {HookCallback} callback - The callback to register
49
- * @returns {Cleanup} - A function to unregister the callback
50
- */
51
- on(type: WatchHook, callback: HookCallback): Cleanup;
52
- }
53
- /**
54
- * Check if the provided value is a State instance
55
- *
56
- * @since 0.9.0
57
- * @param {unknown} value - Value to check
58
- * @returns {boolean} - True if the value is a State instance, false otherwise
59
- */
60
- declare const isState: <T extends {}>(value: unknown) => value is State<T>;
61
- export { TYPE_STATE, isState, State };
@@ -1,51 +0,0 @@
1
- import { type UnknownRecord } from '../diff';
2
- import { type MutableSignal } from '../signal';
3
- import { type Cleanup, type Hook, type HookCallback } from '../system';
4
- import type { List } from './list';
5
- import type { State } from './state';
6
- type Store<T extends UnknownRecord> = BaseStore<T> & {
7
- [K in keyof T]: T[K] extends readonly (infer U extends {})[] ? List<U> : T[K] extends UnknownRecord ? Store<T[K]> : State<T[K] & {}>;
8
- };
9
- declare const TYPE_STORE: "Store";
10
- declare class BaseStore<T extends UnknownRecord> {
11
- #private;
12
- /**
13
- * Create a new store with the given initial value.
14
- *
15
- * @param {T} initialValue - The initial value of the store
16
- * @throws {NullishSignalValueError} - If the initial value is null or undefined
17
- * @throws {InvalidSignalValueError} - If the initial value is not an object
18
- */
19
- constructor(initialValue: T);
20
- get [Symbol.toStringTag](): 'Store';
21
- get [Symbol.isConcatSpreadable](): boolean;
22
- [Symbol.iterator](): IterableIterator<[
23
- string,
24
- MutableSignal<T[keyof T] & {}>
25
- ]>;
26
- keys(): IterableIterator<string>;
27
- byKey<K extends keyof T & string>(key: K): T[K] extends readonly (infer U extends {})[] ? List<U> : T[K] extends UnknownRecord ? Store<T[K]> : T[K] extends unknown & {} ? State<T[K] & {}> : State<T[K] & {}> | undefined;
28
- get(): T;
29
- set(newValue: T): void;
30
- update(fn: (oldValue: T) => T): void;
31
- add<K extends keyof T & string>(key: K, value: T[K]): K;
32
- remove(key: string): void;
33
- on(type: Hook, callback: HookCallback): Cleanup;
34
- }
35
- /**
36
- * Create a new store with deeply nested reactive properties
37
- *
38
- * @since 0.15.0
39
- * @param {T} initialValue - Initial object or array value of the store
40
- * @returns {Store<T>} - New store with reactive properties that preserves the original type T
41
- */
42
- declare const createStore: <T extends UnknownRecord>(initialValue: T) => Store<T>;
43
- /**
44
- * Check if the provided value is a Store instance
45
- *
46
- * @since 0.15.0
47
- * @param {unknown} value - Value to check
48
- * @returns {boolean} - True if the value is a Store instance, false otherwise
49
- */
50
- declare const isStore: <T extends UnknownRecord>(value: unknown) => value is BaseStore<T>;
51
- export { createStore, isStore, BaseStore, TYPE_STORE, type Store };
@@ -1,28 +0,0 @@
1
- type UnknownRecord = Record<string, unknown>;
2
- type UnknownArray = ReadonlyArray<unknown & {}>;
3
- type DiffResult = {
4
- changed: boolean;
5
- add: UnknownRecord;
6
- change: UnknownRecord;
7
- remove: UnknownRecord;
8
- };
9
- /**
10
- * Checks if two values are equal with cycle detection
11
- *
12
- * @since 0.15.0
13
- * @param {T} a - First value to compare
14
- * @param {T} b - Second value to compare
15
- * @param {WeakSet<object>} visited - Set to track visited objects for cycle detection
16
- * @returns {boolean} Whether the two values are equal
17
- */
18
- declare const isEqual: <T>(a: T, b: T, visited?: WeakSet<object>) => boolean;
19
- /**
20
- * Compares two records and returns a result object containing the differences.
21
- *
22
- * @since 0.15.0
23
- * @param {T} oldObj - The old record to compare
24
- * @param {T} newObj - The new record to compare
25
- * @returns {DiffResult} The result of the comparison
26
- */
27
- declare const diff: <T extends UnknownRecord>(oldObj: T, newObj: T) => DiffResult;
28
- export { type DiffResult, diff, isEqual, type UnknownRecord, type UnknownArray };
@@ -1,15 +0,0 @@
1
- import { type Cleanup, type MaybeCleanup } from './system';
2
- type EffectCallback = (() => MaybeCleanup) | ((abort: AbortSignal) => Promise<MaybeCleanup>);
3
- /**
4
- * Define what happens when a reactive state changes
5
- *
6
- * The callback can be synchronous or asynchronous. Async callbacks receive
7
- * an AbortSignal parameter, which is automatically aborted when the effect
8
- * re-runs or is cleaned up, preventing stale async operations.
9
- *
10
- * @since 0.1.0
11
- * @param {EffectCallback} callback - Synchronous or asynchronous effect callback
12
- * @returns {Cleanup} - Cleanup function for the effect
13
- */
14
- declare const createEffect: (callback: EffectCallback) => Cleanup;
15
- export { type MaybeCleanup, type EffectCallback, createEffect };
@@ -1,21 +0,0 @@
1
- import type { ResolveResult } from './resolve';
2
- import type { SignalValues, UnknownSignalRecord } from './signal';
3
- type MatchHandlers<S extends UnknownSignalRecord> = {
4
- ok: (values: SignalValues<S>) => void;
5
- err?: (errors: readonly Error[]) => void;
6
- nil?: () => void;
7
- };
8
- /**
9
- * Match on resolve result and call appropriate handler for side effects
10
- *
11
- * This is a utility function for those who prefer the handler pattern.
12
- * All handlers are for side effects only and return void. If you need
13
- * cleanup logic, use a hoisted let variable in your effect.
14
- *
15
- * @since 0.15.0
16
- * @param {ResolveResult<S>} result - Result from resolve()
17
- * @param {MatchHandlers<S>} handlers - Handlers for different states (side effects only)
18
- * @returns {void} - Always returns void
19
- */
20
- declare function match<S extends UnknownSignalRecord>(result: ResolveResult<S>, handlers: MatchHandlers<S>): void;
21
- export { match, type MatchHandlers };
@@ -1,29 +0,0 @@
1
- import type { SignalValues, UnknownSignalRecord } from './signal';
2
- type ResolveResult<S extends UnknownSignalRecord> = {
3
- ok: true;
4
- values: SignalValues<S>;
5
- errors?: never;
6
- pending?: never;
7
- } | {
8
- ok: false;
9
- errors: readonly Error[];
10
- values?: never;
11
- pending?: never;
12
- } | {
13
- ok: false;
14
- pending: true;
15
- values?: never;
16
- errors?: never;
17
- };
18
- /**
19
- * Resolve signal values with perfect type inference
20
- *
21
- * Always returns a discriminated union result, regardless of whether
22
- * handlers are provided or not. This ensures a predictable API.
23
- *
24
- * @since 0.15.0
25
- * @param {S} signals - Signals to resolve
26
- * @returns {ResolveResult<S>} - Discriminated union result
27
- */
28
- declare function resolve<S extends UnknownSignalRecord>(signals: S): ResolveResult<S>;
29
- export { resolve, type ResolveResult };
@@ -1,81 +0,0 @@
1
- type Cleanup = () => void;
2
- type MaybeCleanup = Cleanup | undefined | void;
3
- type Hook = 'add' | 'change' | 'cleanup' | 'remove' | 'sort' | 'watch';
4
- type CleanupHook = 'cleanup';
5
- type WatchHook = 'watch';
6
- type HookCallback = (payload?: readonly string[]) => MaybeCleanup;
7
- type HookCallbacks = {
8
- [K in Hook]?: Set<HookCallback>;
9
- };
10
- type Watcher = {
11
- (): void;
12
- on(type: CleanupHook, cleanup: Cleanup): void;
13
- stop(): void;
14
- };
15
- declare const UNSET: any;
16
- declare const HOOK_ADD = "add";
17
- declare const HOOK_CHANGE = "change";
18
- declare const HOOK_CLEANUP = "cleanup";
19
- declare const HOOK_REMOVE = "remove";
20
- declare const HOOK_SORT = "sort";
21
- declare const HOOK_WATCH = "watch";
22
- /**
23
- * Create a watcher to observe changes to a signal.
24
- *
25
- * A watcher is a reaction function with onCleanup and stop methods
26
- *
27
- * @since 0.14.1
28
- * @param {() => void} react - Function to be called when the state changes
29
- * @returns {Watcher} - Watcher object with off and cleanup methods
30
- */
31
- declare const createWatcher: (react: () => void) => Watcher;
32
- /**
33
- * Subscribe by adding active watcher to the Set of watchers of a signal.
34
- *
35
- * @param {Set<Watcher>} watchers - Watchers of the signal
36
- * @param {Set<HookCallback>} watchHookCallbacks - HOOK_WATCH callbacks of the signal
37
- */
38
- declare const subscribeActiveWatcher: (watchers: Set<Watcher>, watchHookCallbacks?: Set<HookCallback>) => void;
39
- /**
40
- * Notify watchers of a signal change.
41
- *
42
- * @param {Set<Watcher>} watchers - Watchers of the signal
43
- * @returns {boolean} - Whether any watchers were notified
44
- */
45
- declare const notifyWatchers: (watchers: Set<Watcher>) => boolean;
46
- /**
47
- * Flush all pending reactions of enqueued watchers.
48
- */
49
- declare const flushPendingReactions: () => void;
50
- /**
51
- * Batch multiple signal writes.
52
- *
53
- * @param {() => void} callback - Function with multiple signal writes to be batched
54
- */
55
- declare const batchSignalWrites: (callback: () => void) => void;
56
- /**
57
- * Run a function with signal reads in a tracking context (or temporarily untrack).
58
- *
59
- * @param {Watcher | false} watcher - Watcher to be called when the signal changes
60
- * or false for temporary untracking while inserting auto-hydrating DOM nodes
61
- * that might read signals (e.g., Web Components)
62
- * @param {() => void} run - Function to run the computation or effect
63
- */
64
- declare const trackSignalReads: (watcher: Watcher | false, run: () => void) => void;
65
- /**
66
- * Trigger a hook.
67
- *
68
- * @param {Set<HookCallback> | undefined} callbacks - Callbacks to be called when the hook is triggered
69
- * @param {readonly string[] | undefined} payload - Payload to be sent to listeners
70
- * @return {Cleanup | undefined} Cleanup function to be called when the hook is unmounted
71
- */
72
- declare const triggerHook: (callbacks: Set<HookCallback> | undefined, payload?: readonly string[]) => Cleanup | undefined;
73
- /**
74
- * Check whether a hook type is handled in a signal.
75
- *
76
- * @param {Hook} type - Type of hook to check
77
- * @param {T} handled - List of handled hook types
78
- * @returns {type is T[number]} - Whether the hook type is handled
79
- */
80
- declare const isHandledHook: <T extends readonly Hook[]>(type: Hook, handled: T) => type is T[number];
81
- export { type Cleanup, type MaybeCleanup, type Watcher, type Hook, type CleanupHook, type WatchHook, type HookCallback, type HookCallbacks, HOOK_ADD, HOOK_CHANGE, HOOK_CLEANUP, HOOK_REMOVE, HOOK_SORT, HOOK_WATCH, UNSET, createWatcher, subscribeActiveWatcher, notifyWatchers, flushPendingReactions, batchSignalWrites, trackSignalReads, triggerHook, isHandledHook, };