@but212/atom-effect 0.1.4 → 0.2.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 (68) hide show
  1. package/README.md +8 -8
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +606 -12
  5. package/dist/index.mjs +322 -500
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +4 -4
  8. package/dist/constants.d.ts +0 -64
  9. package/dist/constants.d.ts.map +0 -1
  10. package/dist/core/atom/atom.d.ts +0 -25
  11. package/dist/core/atom/atom.d.ts.map +0 -1
  12. package/dist/core/atom/index.d.ts +0 -6
  13. package/dist/core/atom/index.d.ts.map +0 -1
  14. package/dist/core/computed/computed-async-handler.d.ts +0 -237
  15. package/dist/core/computed/computed-async-handler.d.ts.map +0 -1
  16. package/dist/core/computed/computed-dependencies.d.ts +0 -173
  17. package/dist/core/computed/computed-dependencies.d.ts.map +0 -1
  18. package/dist/core/computed/computed-handlers.d.ts +0 -285
  19. package/dist/core/computed/computed-handlers.d.ts.map +0 -1
  20. package/dist/core/computed/computed-state-flags.d.ts +0 -335
  21. package/dist/core/computed/computed-state-flags.d.ts.map +0 -1
  22. package/dist/core/computed/index.d.ts +0 -35
  23. package/dist/core/computed/index.d.ts.map +0 -1
  24. package/dist/core/effect/effect.d.ts +0 -64
  25. package/dist/core/effect/effect.d.ts.map +0 -1
  26. package/dist/core/effect/index.d.ts +0 -2
  27. package/dist/core/effect/index.d.ts.map +0 -1
  28. package/dist/core/index.d.ts +0 -4
  29. package/dist/core/index.d.ts.map +0 -1
  30. package/dist/errors/errors.d.ts +0 -118
  31. package/dist/errors/errors.d.ts.map +0 -1
  32. package/dist/errors/messages.d.ts +0 -101
  33. package/dist/errors/messages.d.ts.map +0 -1
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/scheduler/batch.d.ts +0 -31
  36. package/dist/scheduler/batch.d.ts.map +0 -1
  37. package/dist/scheduler/index.d.ts +0 -3
  38. package/dist/scheduler/index.d.ts.map +0 -1
  39. package/dist/scheduler/scheduler.d.ts +0 -153
  40. package/dist/scheduler/scheduler.d.ts.map +0 -1
  41. package/dist/tracking/context.d.ts +0 -76
  42. package/dist/tracking/context.d.ts.map +0 -1
  43. package/dist/tracking/dependency-manager.d.ts +0 -224
  44. package/dist/tracking/dependency-manager.d.ts.map +0 -1
  45. package/dist/tracking/index.d.ts +0 -5
  46. package/dist/tracking/index.d.ts.map +0 -1
  47. package/dist/tracking/tracking.types.d.ts +0 -12
  48. package/dist/tracking/tracking.types.d.ts.map +0 -1
  49. package/dist/tracking/untracked.d.ts +0 -25
  50. package/dist/tracking/untracked.d.ts.map +0 -1
  51. package/dist/types/atom.d.ts +0 -13
  52. package/dist/types/atom.d.ts.map +0 -1
  53. package/dist/types/common.d.ts +0 -45
  54. package/dist/types/common.d.ts.map +0 -1
  55. package/dist/types/computed.d.ts +0 -18
  56. package/dist/types/computed.d.ts.map +0 -1
  57. package/dist/types/effect.d.ts +0 -13
  58. package/dist/types/effect.d.ts.map +0 -1
  59. package/dist/types/index.d.ts +0 -5
  60. package/dist/types/index.d.ts.map +0 -1
  61. package/dist/utils/debug.d.ts +0 -85
  62. package/dist/utils/debug.d.ts.map +0 -1
  63. package/dist/utils/object-pool.d.ts +0 -159
  64. package/dist/utils/object-pool.d.ts.map +0 -1
  65. package/dist/utils/subscriber-manager.d.ts +0 -127
  66. package/dist/utils/subscriber-manager.d.ts.map +0 -1
  67. package/dist/utils/type-guards.d.ts +0 -5
  68. package/dist/utils/type-guards.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@but212/atom-effect",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "A reactive state management library that combines the power of `atom`, `computed`, and `effect` for seamless management of reactive state.",
6
- "main": "dist/index.cjs",
7
- "module": "dist/index.mjs",
8
- "types": "dist/index.d.ts",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist"
11
11
  ],
@@ -1,64 +0,0 @@
1
- /**
2
- * @fileoverview Constants and configuration for atom-effect library
3
- * @description Centralized constants for async states, bit flags, and performance tuning
4
- */
5
- /**
6
- * Async computation states for computed atoms
7
- */
8
- export declare const AsyncState: {
9
- IDLE: "idle";
10
- PENDING: "pending";
11
- RESOLVED: "resolved";
12
- REJECTED: "rejected";
13
- };
14
- /**
15
- * Bit flags for effect state management
16
- * Using bit flags for efficient state checks (O(1) operations)
17
- */
18
- export declare const EFFECT_STATE_FLAGS: {
19
- readonly DISPOSED: number;
20
- readonly EXECUTING: number;
21
- };
22
- /**
23
- * Bit flags for computed atom state management
24
- * Enables fast state transitions and checks without multiple boolean fields
25
- */
26
- export declare const COMPUTED_STATE_FLAGS: {
27
- readonly DIRTY: number;
28
- readonly IDLE: number;
29
- readonly PENDING: number;
30
- readonly RESOLVED: number;
31
- readonly REJECTED: number;
32
- readonly RECOMPUTING: number;
33
- readonly HAS_ERROR: number;
34
- };
35
- /**
36
- * Object pool configuration
37
- * Controls memory management and GC pressure reduction
38
- */
39
- export declare const POOL_CONFIG: {
40
- /** Maximum number of pooled objects to prevent memory bloat */
41
- readonly MAX_SIZE: 1000;
42
- /** Number of objects to pre-allocate for performance-critical paths */
43
- readonly WARMUP_SIZE: 100;
44
- };
45
- /**
46
- * Scheduler configuration
47
- * Controls batching behavior and performance limits
48
- */
49
- export declare const SCHEDULER_CONFIG: {
50
- /** Maximum effect executions per second to detect infinite loops */
51
- readonly MAX_EXECUTIONS_PER_SECOND: 100;
52
- /** Threshold for cleaning up old execution timestamps */
53
- readonly CLEANUP_THRESHOLD: 100;
54
- };
55
- /**
56
- * Debug configuration defaults
57
- */
58
- export declare const DEBUG_CONFIG: {
59
- /** Maximum dependencies before warning about large dependency graphs */
60
- readonly MAX_DEPENDENCIES: 1000;
61
- /** Enable infinite loop detection warnings */
62
- readonly WARN_INFINITE_LOOP: true;
63
- };
64
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;CAKtB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;CAGrB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;CAQvB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,WAAW;IACtB,+DAA+D;;IAE/D,uEAAuE;;CAE/D,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,gBAAgB;IAC3B,oEAAoE;;IAEpE,yDAAyD;;CAEjD,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,YAAY;IACvB,wEAAwE;;IAExE,8CAA8C;;CAEtC,CAAC"}
@@ -1,25 +0,0 @@
1
- import { AtomOptions, WritableAtom } from '../../types';
2
- /**
3
- * Creates a new atom with the given initial value.
4
- *
5
- * @template T - The type of value stored in the atom
6
- * @param initialValue - The initial value of the atom
7
- * @param options - Optional configuration options
8
- * @returns A writable atom instance
9
- *
10
- * @example
11
- * ```ts
12
- * // Basic usage
13
- * const count = atom(0);
14
- *
15
- * // With sync option for immediate notifications
16
- * const syncCount = atom(0, { sync: true });
17
- *
18
- * // Reading and writing
19
- * console.log(count.value); // 0
20
- * count.value = 5;
21
- * console.log(count.peek()); // 5 (non-tracking read)
22
- * ```
23
- */
24
- export declare function atom<T>(initialValue: T, options?: AtomOptions): WritableAtom<T>;
25
- //# sourceMappingURL=atom.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"atom.d.ts","sourceRoot":"","sources":["../../../src/core/atom/atom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAc,YAAY,EAAE,MAAM,aAAa,CAAC;AAqPzE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,GAAE,WAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,CAEnF"}
@@ -1,6 +0,0 @@
1
- /**
2
- * @fileoverview Atom module exports
3
- * @description Re-exports all atom-related functionality including the atom factory function and types
4
- */
5
- export * from './atom';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/atom/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,QAAQ,CAAC"}
@@ -1,237 +0,0 @@
1
- import { AtomError } from '../../errors/errors';
2
- import { ComputedStateFlags } from './computed-state-flags';
3
- /**
4
- * Promise ID manager to prevent race conditions in async computed values.
5
- *
6
- * @description
7
- * Generates and tracks unique IDs for async computations. When a new computation
8
- * starts, it receives a new ID. If a previous computation completes after a newer
9
- * one has started, its ID will no longer be valid, and its result will be discarded.
10
- *
11
- * @remarks
12
- * - IDs are monotonically increasing integers
13
- * - Overflow protection wraps around at MAX_SAFE_INTEGER
14
- * - Thread-safe for single-threaded JavaScript execution
15
- *
16
- * @example
17
- * ```ts
18
- * const manager = new PromiseIdManager();
19
- *
20
- * const id1 = manager.next(); // 1
21
- * const id2 = manager.next(); // 2
22
- *
23
- * manager.isValid(id1); // false - superseded by id2
24
- * manager.isValid(id2); // true - current ID
25
- *
26
- * manager.invalidate(); // Increments to 3, invalidating id2
27
- * ```
28
- */
29
- export declare class PromiseIdManager {
30
- /**
31
- * The most recently generated Promise ID.
32
- * Used to track the current/latest computation.
33
- * @private
34
- */
35
- private lastPromiseId;
36
- /**
37
- * Maximum allowed Promise ID before overflow wrap-around.
38
- * Set to MAX_SAFE_INTEGER - 1 to ensure safe increment operations.
39
- * @private
40
- * @readonly
41
- */
42
- private readonly MAX_PROMISE_ID;
43
- /**
44
- * Generates the next unique Promise ID with overflow protection.
45
- *
46
- * @description
47
- * Increments the internal counter and returns the new ID.
48
- * If the counter reaches MAX_SAFE_INTEGER, it wraps around to 0
49
- * to prevent integer overflow issues.
50
- *
51
- * @returns A new unique Promise ID
52
- *
53
- * @example
54
- * ```ts
55
- * const manager = new PromiseIdManager();
56
- * const id = manager.next(); // Returns 1, 2, 3, ...
57
- * ```
58
- */
59
- next(): number;
60
- /**
61
- * Gets the current (most recent) Promise ID without incrementing.
62
- *
63
- * @description
64
- * Returns the ID of the most recently started computation.
65
- * Useful for checking the current state without side effects.
66
- *
67
- * @returns The current Promise ID
68
- *
69
- * @example
70
- * ```ts
71
- * const manager = new PromiseIdManager();
72
- * manager.next(); // 1
73
- * manager.current(); // 1 (doesn't increment)
74
- * ```
75
- */
76
- current(): number;
77
- /**
78
- * Checks if a Promise ID is still valid (not superseded by newer computation).
79
- *
80
- * @description
81
- * A Promise ID is valid only if it matches the current ID, meaning no newer
82
- * computation has been started since this ID was generated.
83
- *
84
- * @param id - The Promise ID to validate
85
- * @returns true if the ID is current and valid, false if superseded
86
- *
87
- * @example
88
- * ```ts
89
- * const manager = new PromiseIdManager();
90
- * const id1 = manager.next(); // 1
91
- * manager.isValid(id1); // true
92
- *
93
- * const id2 = manager.next(); // 2
94
- * manager.isValid(id1); // false - superseded
95
- * manager.isValid(id2); // true
96
- * ```
97
- */
98
- isValid(id: number): boolean;
99
- /**
100
- * Invalidates all previous computations by incrementing the Promise ID.
101
- *
102
- * @description
103
- * Call this method to cancel/ignore results from all pending computations.
104
- * Useful when manually triggering a recomputation or during cleanup.
105
- *
106
- * @example
107
- * ```ts
108
- * const manager = new PromiseIdManager();
109
- * const id = manager.next();
110
- * manager.isValid(id); // true
111
- *
112
- * manager.invalidate();
113
- * manager.isValid(id); // false - invalidated
114
- * ```
115
- */
116
- invalidate(): void;
117
- }
118
- /**
119
- * Async computation handler for computed atoms.
120
- *
121
- * @description
122
- * Manages the complete lifecycle of asynchronous computations:
123
- * 1. Sets pending state when computation starts
124
- * 2. Handles successful resolution with value updates
125
- * 3. Handles rejection with error state management
126
- * 4. Prevents race conditions using PromiseIdManager
127
- * 5. Notifies subscribers of state changes
128
- *
129
- * @template T - The type of value produced by the async computation
130
- *
131
- * @remarks
132
- * - Only the most recent computation's result is applied
133
- * - State transitions: IDLE → PENDING → RESOLVED | REJECTED
134
- * - Subscribers are notified on value changes and errors
135
- * - Custom error handlers are supported via onError callback
136
- *
137
- * @example
138
- * ```ts
139
- * const handler = new AsyncComputationHandler<User>(
140
- * stateFlags,
141
- * promiseIdManager,
142
- * (a, b) => a.id === b.id, // equality function
143
- * (error) => console.error(error), // error handler
144
- * () => notifyAllSubscribers() // notification callback
145
- * );
146
- *
147
- * // Handle an async computation
148
- * handler.handle(
149
- * fetchUser(userId),
150
- * () => currentUser,
151
- * (user) => { currentUser = user; },
152
- * (error) => { lastError = error; }
153
- * );
154
- * ```
155
- */
156
- export declare class AsyncComputationHandler<T> {
157
- private stateFlags;
158
- private promiseIdManager;
159
- private equal;
160
- private onError;
161
- private notifySubscribers;
162
- /**
163
- * Creates a new AsyncComputationHandler instance.
164
- *
165
- * @param stateFlags - State manager for tracking computation status
166
- * @param promiseIdManager - Manager for race condition prevention
167
- * @param equal - Equality function to compare values
168
- * @param onError - Optional error callback
169
- * @param notifySubscribers - Callback to notify subscribers of changes
170
- */
171
- constructor(stateFlags: ComputedStateFlags, promiseIdManager: PromiseIdManager, equal: (a: T, b: T) => boolean, onError: ((error: Error) => void) | null, notifySubscribers: () => void);
172
- /**
173
- * Handles an async computation Promise.
174
- *
175
- * @description
176
- * Initiates handling of a Promise-based computation:
177
- * 1. Sets state to PENDING
178
- * 2. Generates a unique Promise ID for race condition tracking
179
- * 3. Attaches then/catch handlers for resolution/rejection
180
- * 4. Validates Promise ID before applying results
181
- *
182
- * @param result - The Promise to handle
183
- * @param getValue - Getter function for the current cached value
184
- * @param setValue - Setter function for updating the cached value
185
- * @param setError - Setter function for error state
186
- *
187
- * @example
188
- * ```ts
189
- * handler.handle(
190
- * fetch('/api/data').then(r => r.json()),
191
- * () => cachedData,
192
- * (data) => { cachedData = data; },
193
- * (error) => { lastError = error; }
194
- * );
195
- * ```
196
- */
197
- handle(result: Promise<T>, getValue: () => T, setValue: (value: T) => void, setError: (error: AtomError | null) => void): void;
198
- /**
199
- * Handles successful Promise resolution.
200
- *
201
- * @description
202
- * Called when an async computation completes successfully:
203
- * 1. Determines if the value has changed (using equality function)
204
- * 2. Updates the cached value
205
- * 3. Clears dirty flag and sets resolved state
206
- * 4. Clears any previous error
207
- * 5. Notifies subscribers if value changed
208
- *
209
- * @private
210
- * @param resolvedValue - The resolved value from the Promise
211
- * @param getValue - Getter for current cached value
212
- * @param setValue - Setter for cached value
213
- * @param setError - Setter for error state
214
- */
215
- private handleResolution;
216
- /**
217
- * Handles Promise rejection.
218
- *
219
- * @description
220
- * Called when an async computation fails:
221
- * 1. Wraps the error in a ComputedError for consistent error handling
222
- * 2. Sets the error state
223
- * 3. Updates state flags to rejected
224
- * 4. Invokes the onError callback if provided
225
- * 5. Notifies subscribers of the error state
226
- *
227
- * @private
228
- * @param err - The error/rejection reason from the Promise
229
- * @param setError - Setter for error state
230
- *
231
- * @remarks
232
- * Errors in the onError callback are caught and logged to prevent
233
- * cascading failures.
234
- */
235
- private handleRejection;
236
- }
237
- //# sourceMappingURL=computed-async-handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"computed-async-handler.d.ts","sourceRoot":"","sources":["../../../src/core/computed/computed-async-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,gBAAgB;IAC3B;;;;OAIG;IACH,OAAO,CAAC,aAAa,CAAK;IAE1B;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA+B;IAE9D;;;;;;;;;;;;;;;OAeG;IACH,IAAI,IAAI,MAAM;IAQd;;;;;;;;;;;;;;;OAeG;IACH,OAAO,IAAI,MAAM;IAIjB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI5B;;;;;;;;;;;;;;;;OAgBG;IACH,UAAU,IAAI,IAAI;CAGnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAAa,uBAAuB,CAAC,CAAC;IAWlC,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,iBAAiB;IAd3B;;;;;;;;OAQG;gBAEO,UAAU,EAAE,kBAAkB,EAC9B,gBAAgB,EAAE,gBAAgB,EAClC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,EAC9B,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,EACxC,iBAAiB,EAAE,MAAM,IAAI;IAGvC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CACJ,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAClB,QAAQ,EAAE,MAAM,CAAC,EACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAC5B,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,GAC1C,IAAI;IAoBP;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,eAAe;CAkBxB"}
@@ -1,173 +0,0 @@
1
- import { DependencyManager } from '../../tracking/dependency-manager';
2
- /**
3
- * Manages dependency synchronization for computed values.
4
- *
5
- * Uses a delta sync algorithm to efficiently update dependencies by:
6
- * 1. Fast path: O(1) check if no changes occurred
7
- * 2. Slow path: Only subscribe/unsubscribe changed dependencies
8
- *
9
- * @example
10
- * ```typescript
11
- * const syncManager = new DependencySyncManager(depManager, computed, markDirty);
12
- *
13
- * // During recomputation, collect new dependencies
14
- * const newDeps = new Set<unknown>();
15
- * // ... computation that populates newDeps ...
16
- *
17
- * // Efficiently sync dependencies
18
- * syncManager.update(newDeps);
19
- * ```
20
- *
21
- * @remarks
22
- * - WeakMap is used internally for automatic garbage collection
23
- * - Circular dependency detection is performed on each new subscription
24
- * - Thread-safe for single-threaded JavaScript execution
25
- */
26
- export declare class DependencySyncManager {
27
- private dependencyManager;
28
- private computedObject;
29
- private markDirty;
30
- /**
31
- * Creates a new DependencySyncManager instance.
32
- *
33
- * @param dependencyManager - The underlying dependency manager for subscription handling
34
- * @param computedObject - Reference to the computed object for circular detection
35
- * @param markDirty - Callback invoked when any dependency changes
36
- *
37
- * @throws If dependencyManager is null or undefined
38
- */
39
- constructor(dependencyManager: DependencyManager, computedObject: unknown, markDirty: () => void);
40
- /**
41
- * Updates dependencies using the delta sync algorithm.
42
- *
43
- * This method compares the current dependencies with new ones and
44
- * performs minimal subscription changes for optimal performance.
45
- *
46
- * @param newDeps - Set of dependencies detected during the latest computation
47
- *
48
- * @remarks
49
- * Performance characteristics:
50
- * - Best case (no changes): O(n) where n is dependency count
51
- * - Worst case (all changed): O(n + m) where m is new dependency count
52
- *
53
- * @example
54
- * ```typescript
55
- * const newDeps = new Set([atomA, atomB, computedC]);
56
- * syncManager.update(newDeps);
57
- * ```
58
- */
59
- update(newDeps: Set<unknown>): void;
60
- /**
61
- * Checks if current dependencies are identical to new dependencies.
62
- *
63
- * This is the fast path optimization that avoids expensive subscription
64
- * operations when dependencies haven't changed.
65
- *
66
- * @param current - Array of current dependencies
67
- * @param newDeps - Set of new dependencies to compare
68
- * @returns True if dependencies are identical, false otherwise
69
- *
70
- * @remarks
71
- * Time complexity: O(n) where n is the number of current dependencies
72
- * Space complexity: O(1)
73
- */
74
- private hasSameDependencies;
75
- /**
76
- * Performs delta synchronization between current and new dependencies.
77
- *
78
- * This method:
79
- * 1. Identifies dependencies to remove (in current but not in new)
80
- * 2. Identifies dependencies to add (in new but not in current)
81
- * 3. Unsubscribes from removed dependencies
82
- * 4. Subscribes to new dependencies
83
- * 5. Updates the internal dependency array
84
- *
85
- * @param current - Array of current dependencies (will be mutated)
86
- * @param newDeps - Set of new dependencies
87
- *
88
- * @remarks
89
- * Time complexity: O(n + m) where n is current count and m is new count
90
- * Space complexity: O(n + m) for temporary sets and arrays
91
- */
92
- private performDeltaSync;
93
- /**
94
- * Adds a single dependency with circular reference detection.
95
- *
96
- * @param dep - The dependency to add and subscribe to
97
- *
98
- * @throws If circular dependency is detected
99
- * @throws If subscription fails for any reason
100
- *
101
- * @remarks
102
- * This method performs circular reference detection before subscribing
103
- * to prevent infinite loops in the dependency graph.
104
- */
105
- private addDependency;
106
- /**
107
- * Gets the current number of active dependencies.
108
- *
109
- * @returns The count of dependencies currently being tracked
110
- *
111
- * @remarks
112
- * This count may be less than the total subscriptions made if some
113
- * dependencies have been garbage collected (due to WeakRef usage).
114
- */
115
- getDependencyCount(): number;
116
- /**
117
- * Checks if dependency count exceeds the configured threshold and warns.
118
- *
119
- * Large dependency graphs can indicate architectural issues and may
120
- * cause performance problems. This method helps identify such cases.
121
- *
122
- * @remarks
123
- * The warning threshold is configured via `debug.maxDependencies`.
124
- * Warnings are only emitted in development mode when debug is enabled.
125
- *
126
- * @see {@link debug.maxDependencies} for threshold configuration
127
- */
128
- checkDependencyLimit(): void;
129
- }
130
- /**
131
- * Temporary dependency tracker returned by createDependencyTracker.
132
- *
133
- * @remarks
134
- * This type combines a callable function with dependency tracking methods.
135
- */
136
- export type DependencyTrackerFunction = (() => void) & {
137
- /**
138
- * Adds a dependency to be tracked during computation.
139
- * @param dep - The dependency to track
140
- */
141
- addDependency: (dep: unknown) => void;
142
- /**
143
- * Gets all collected dependencies.
144
- * @returns Set of all tracked dependencies
145
- */
146
- getDependencies: () => Set<unknown>;
147
- };
148
- /**
149
- * Creates a temporary dependency tracker for a single computation cycle.
150
- *
151
- * This factory function creates a tracker that collects dependencies
152
- * during a computation and can be used with the tracking context.
153
- *
154
- * @param markDirty - Callback to invoke when the computation needs rerun
155
- * @returns A tracking function with addDependency and getDependencies methods
156
- *
157
- * @example
158
- * ```typescript
159
- * const tracker = createDependencyTracker(() => markDirty());
160
- *
161
- * // Use in tracking context
162
- * const result = trackingContext.run(tracker, computeFn);
163
- *
164
- * // Get collected dependencies
165
- * const deps = tracker.getDependencies();
166
- * ```
167
- *
168
- * @remarks
169
- * The returned tracker is designed for single-use during one computation.
170
- * Create a new tracker for each recomputation cycle.
171
- */
172
- export declare function createDependencyTracker(markDirty: () => void): DependencyTrackerFunction;
173
- //# sourceMappingURL=computed-dependencies.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"computed-dependencies.d.ts","sourceRoot":"","sources":["../../../src/core/computed/computed-dependencies.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAI3E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,qBAAqB;IAW9B,OAAO,CAAC,iBAAiB;IACzB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,SAAS;IAZnB;;;;;;;;OAQG;gBAEO,iBAAiB,EAAE,iBAAiB,EACpC,cAAc,EAAE,OAAO,EACvB,SAAS,EAAE,MAAM,IAAI;IAG/B;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI;IAYnC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,mBAAmB;IAc3B;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,gBAAgB;IAqCxB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,aAAa;IAWrB;;;;;;;;OAQG;IACH,kBAAkB,IAAI,MAAM;IAI5B;;;;;;;;;;;OAWG;IACH,oBAAoB,IAAI,IAAI;CAI7B;AAED;;;;;GAKG;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG;IACrD;;;OAGG;IACH,aAAa,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAEtC;;;OAGG;IACH,eAAe,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,IAAI,GAAG,yBAAyB,CAOxF"}