@but212/atom-effect 0.1.3 → 0.1.5

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 +7 -7
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +583 -12
  5. package/dist/index.mjs +79 -85
  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
@@ -1,224 +0,0 @@
1
- import { Dependency } from '../types';
2
- /**
3
- * Manages reactive dependencies with automatic cleanup and memory-efficient tracking.
4
- *
5
- * This class provides a centralized way to track dependencies between reactive
6
- * primitives (atoms, computed values) and their subscribers. It uses WeakRef
7
- * and WeakMap for memory-efficient storage that allows garbage collection
8
- * of unused dependencies.
9
- *
10
- * @remarks
11
- * - Uses WeakMap for O(1) lookup and automatic GC of unreferenced dependencies
12
- * - Uses WeakRef array for iteration while allowing GC
13
- * - Periodic cleanup removes stale WeakRefs to prevent memory leaks
14
- * - Thread-safe for single-threaded JavaScript execution
15
- *
16
- * @example
17
- * ```typescript
18
- * const manager = new DependencyManager();
19
- *
20
- * // Add a dependency with its unsubscribe callback
21
- * const unsubscribe = atom.subscribe(() => recompute());
22
- * manager.addDependency(atom, unsubscribe);
23
- *
24
- * // Check if dependency exists
25
- * if (manager.hasDependency(atom)) {
26
- * console.log('Dependency tracked');
27
- * }
28
- *
29
- * // Remove specific dependency
30
- * manager.removeDependency(atom);
31
- *
32
- * // Clean up all dependencies
33
- * manager.unsubscribeAll();
34
- * ```
35
- */
36
- export declare class DependencyManager {
37
- /**
38
- * Array of tracked dependencies.
39
- * Managed as a simple array for maximum performance (no WeakRef overhead).
40
- */
41
- private readonly depRefs;
42
- /**
43
- * Map of dependencies to their unsubscribe functions.
44
- * WeakMap ensures automatic cleanup when dependency is garbage collected.
45
- */
46
- private readonly depMap;
47
- /** Current number of active dependencies */
48
- private count;
49
- /**
50
- * Number of additions before triggering automatic cleanup.
51
- * @defaultValue 100
52
- */
53
- private cleanupThreshold;
54
- /**
55
- * Counter tracking additions since last cleanup.
56
- */
57
- private addCount;
58
- constructor();
59
- /**
60
- * Adds a dependency with its associated unsubscribe callback.
61
- *
62
- * If the dependency already exists, the new unsubscribe callback is
63
- * immediately called to prevent duplicate subscriptions.
64
- *
65
- * @param dep - The dependency to track (atom, computed, etc.)
66
- * @param cleanup - Callback to invoke when removing the dependency
67
- *
68
- * @remarks
69
- * - Duplicate dependencies are rejected with immediate unsubscribe
70
- * - Automatic cleanup is triggered every `cleanupThreshold` additions
71
- * - Time complexity: O(1) for add, O(n) when cleanup triggers
72
- *
73
- * @example
74
- * ```typescript
75
- * const unsubscribe = atom.subscribe(() => markDirty());
76
- * manager.addDependency(atom, unsubscribe);
77
- * ```
78
- */
79
- addDependency(dep: Dependency, cleanup: () => void): void;
80
- /**
81
- * Removes a dependency and calls its unsubscribe callback.
82
- *
83
- * @param dep - The dependency to remove
84
- * @returns `true` if the dependency was found and removed, `false` otherwise
85
- *
86
- * @remarks
87
- * - Unsubscribe errors are caught and logged to prevent cascading failures
88
- * - The WeakRef entry is not immediately removed (cleaned up lazily)
89
- * - Time complexity: O(1)
90
- *
91
- * @example
92
- * ```typescript
93
- * const wasRemoved = manager.removeDependency(atom);
94
- * if (wasRemoved) {
95
- * console.log('Dependency successfully removed');
96
- * }
97
- * ```
98
- */
99
- removeDependency(dep: Dependency): boolean;
100
- /**
101
- * Checks if a dependency is currently being tracked.
102
- *
103
- * @param dep - The dependency to check
104
- * @returns `true` if the dependency exists in the manager
105
- *
106
- * @remarks
107
- * Time complexity: O(1)
108
- *
109
- * @example
110
- * ```typescript
111
- * if (manager.hasDependency(atom)) {
112
- * // Dependency is already tracked
113
- * }
114
- * ```
115
- */
116
- hasDependency(dep: Dependency): boolean;
117
- /**
118
- * Removes all dependencies and calls their unsubscribe callbacks.
119
- *
120
- * This method iterates through all tracked dependencies, calls their
121
- * unsubscribe callbacks, and clears internal storage.
122
- *
123
- * @remarks
124
- * - Errors during unsubscribe are caught and logged individually
125
- * - Safe to call multiple times (idempotent after first call)
126
- * - Time complexity: O(n) where n is the number of dependencies
127
- *
128
- * @example
129
- * ```typescript
130
- * // Clean up when disposing a computed value
131
- * manager.unsubscribeAll();
132
- * ```
133
- */
134
- unsubscribeAll(): void;
135
- /**
136
- * Removes stale references from the internal array.
137
- *
138
- * This method iterates through the `depRefs` array and removes any dependencies
139
- * that are no longer present in the `depMap` (meaning their unsubscribe
140
- * callback has been garbage collected or explicitly deleted).
141
- *
142
- * @remarks
143
- * - Called automatically every `cleanupThreshold` additions
144
- * - Can be called manually for immediate cleanup
145
- * - Time complexity: O(n) where n is the number of dependencies
146
- *
147
- * @example
148
- * ```typescript
149
- * // Force immediate cleanup
150
- * manager.cleanup();
151
- * ```
152
- */
153
- cleanup(): void;
154
- /**
155
- * Gets the current number of live dependencies.
156
- *
157
- * @returns The count of dependencies that haven't been garbage collected
158
- *
159
- * @remarks
160
- * - Triggers cleanup before counting for accurate results
161
- * - Time complexity: O(n) due to cleanup
162
- *
163
- * @example
164
- * ```typescript
165
- * console.log(`Tracking ${manager.count} dependencies`);
166
- * ```
167
- */
168
- get liveCount(): number;
169
- /**
170
- * Gets an array of all live dependencies.
171
- *
172
- * @returns Array of dependencies that haven't been garbage collected
173
- *
174
- * @remarks
175
- * - Returns a new array (safe to modify)
176
- * - Does not trigger cleanup (may include some stale refs)
177
- * - Time complexity: O(n)
178
- *
179
- * @example
180
- * ```typescript
181
- * const deps = manager.getDependencies();
182
- * deps.forEach(dep => console.log(dep));
183
- * ```
184
- */
185
- getDependencies(): Dependency[];
186
- /**
187
- * Gets the internal WeakMap for advanced use cases.
188
- *
189
- * @returns The internal dependency -> unsubscribe WeakMap
190
- *
191
- * @remarks
192
- * - Returns the actual internal map (not a copy)
193
- * - Modifications will affect the manager's state
194
- * - Use with caution in production code
195
- *
196
- * @example
197
- * ```typescript
198
- * const map = manager.getDepMap();
199
- * const unsubscribe = map.get(someDependency);
200
- * ```
201
- */
202
- getDepMap(): WeakMap<Dependency, () => void>;
203
- /**
204
- * Sets the threshold for automatic cleanup triggering.
205
- *
206
- * @param threshold - Number of additions before cleanup (minimum 1)
207
- *
208
- * @remarks
209
- * - Lower values mean more frequent cleanup (less memory, more CPU)
210
- * - Higher values mean less frequent cleanup (more memory, less CPU)
211
- * - Default is 100, suitable for most use cases
212
- *
213
- * @example
214
- * ```typescript
215
- * // More aggressive cleanup for memory-constrained environments
216
- * manager.setCleanupThreshold(50);
217
- *
218
- * // Less frequent cleanup for performance-critical paths
219
- * manager.setCleanupThreshold(500);
220
- * ```
221
- */
222
- setCleanupThreshold(threshold: number): void;
223
- }
224
- //# sourceMappingURL=dependency-manager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dependency-manager.d.ts","sourceRoot":"","sources":["../../src/tracking/dependency-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,iBAAiB;IAC5B;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAE5C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IAEzD,4CAA4C;IAC5C,OAAO,CAAC,KAAK,CAAS;IAEtB;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CAAO;IAE/B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAK;;IAQrB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI;IAoBzD;;;;;;;;;;;;;;;;;;OAkBG;IACH,gBAAgB,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO;IAwC1C;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO;IAKvC;;;;;;;;;;;;;;;;OAgBG;IACH,cAAc,IAAI,IAAI;IAqBtB;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,IAAI,IAAI;IA8Bf;;;;;;;;;;;;;OAaG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;;;;;;;;;;;;;;OAeG;IACH,eAAe,IAAI,UAAU,EAAE;IAW/B;;;;;;;;;;;;;;;OAeG;IACH,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC;IAI5C;;;;;;;;;;;;;;;;;;OAkBG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAG7C"}
@@ -1,5 +0,0 @@
1
- export * from './context';
2
- export * from './dependency-manager';
3
- export * from './tracking.types';
4
- export * from './untracked';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tracking/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Interface for listeners that can track dependencies
3
- */
4
- export interface DependencyTracker {
5
- addDependency?: (dep: unknown) => void;
6
- execute?: () => void;
7
- }
8
- /**
9
- * Listener type
10
- */
11
- export type Listener = DependencyTracker | (() => void);
12
- //# sourceMappingURL=tracking.types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tracking.types.d.ts","sourceRoot":"","sources":["../../src/tracking/tracking.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,iBAAiB,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC"}
@@ -1,25 +0,0 @@
1
- /**
2
- * Executes a function without tracking any reactive dependencies.
3
- *
4
- * This utility allows reading atom values without establishing
5
- * a dependency relationship, useful for accessing values that
6
- * shouldn't trigger recomputation when they change.
7
- *
8
- * @template T - The return type of the function
9
- * @param fn - The function to execute without tracking
10
- * @returns The result of the executed function
11
- * @throws {AtomError} If the callback is not a function
12
- * @throws {AtomError} If an error occurs during execution
13
- *
14
- * @example
15
- * ```typescript
16
- * const count = atom(0);
17
- * const doubled = computed(() => {
18
- * // This read will NOT be tracked as a dependency
19
- * const untrackedValue = untracked(() => count.value);
20
- * return untrackedValue * 2;
21
- * });
22
- * ```
23
- */
24
- export declare function untracked<T>(fn: () => T): T;
25
- //# sourceMappingURL=untracked.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"untracked.d.ts","sourceRoot":"","sources":["../../src/tracking/untracked.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAe3C"}
@@ -1,13 +0,0 @@
1
- export interface AtomOptions {
2
- sync?: boolean;
3
- }
4
- export interface ReadonlyAtom<T = unknown> {
5
- readonly value: T;
6
- subscribe(listener: (newValue?: T, oldValue?: T) => void): () => void;
7
- peek(): T;
8
- }
9
- export interface WritableAtom<T = unknown> extends ReadonlyAtom<T> {
10
- value: T;
11
- dispose(): void;
12
- }
13
- //# sourceMappingURL=atom.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"atom.d.ts","sourceRoot":"","sources":["../../src/types/atom.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACtE,IAAI,IAAI,CAAC,CAAC;CACX;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAChE,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,IAAI,IAAI,CAAC;CACjB"}
@@ -1,45 +0,0 @@
1
- /**
2
- * Interface for poolable objects
3
- */
4
- export interface Poolable {
5
- reset(): void;
6
- }
7
- /**
8
- * Subscriber interface for dependency notifications
9
- */
10
- export interface Subscriber {
11
- execute(): void;
12
- }
13
- /**
14
- * Interface for subscribable dependencies
15
- */
16
- export interface Dependency {
17
- subscribe(listener: (() => void) | Subscriber): () => void;
18
- peek?(): unknown;
19
- value?: unknown;
20
- }
21
- /**
22
- * WeakRef-based dependency entry structure
23
- */
24
- export interface DependencyEntry<T extends object = Dependency> {
25
- ref: WeakRef<T>;
26
- unsubscribe: () => void;
27
- }
28
- /**
29
- * Debug configuration interface
30
- */
31
- export interface DebugConfig {
32
- enabled: boolean;
33
- maxDependencies: number;
34
- warnInfiniteLoop: boolean;
35
- warn(condition: boolean, message: string): void;
36
- checkCircular(dep: unknown, current: unknown, visited?: Set<unknown>): void;
37
- attachDebugInfo(obj: object, type: string, id: number): void;
38
- getDebugName(obj: unknown): string | undefined;
39
- getDebugType(obj: unknown): string | undefined;
40
- }
41
- /**
42
- * Transform function type
43
- */
44
- export type TransformFunction<T, U> = (value: T) => U;
45
- //# sourceMappingURL=common.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,UAAU,GAAG,MAAM,IAAI,CAAC;IAC3D,IAAI,CAAC,IAAI,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,UAAU;IAC5D,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAChB,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5E,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7D,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IAC/C,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;CAChD;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC"}
@@ -1,18 +0,0 @@
1
- import { ReadonlyAtom } from './atom';
2
- export type AsyncStateType = 'idle' | 'pending' | 'resolved' | 'rejected';
3
- export interface ComputedOptions<T = unknown> {
4
- equal?: (a: T, b: T) => boolean;
5
- defaultValue?: T;
6
- lazy?: boolean;
7
- onError?: (error: Error) => void;
8
- }
9
- export interface ComputedAtom<T = unknown> extends ReadonlyAtom<T> {
10
- readonly state: AsyncStateType;
11
- readonly hasError: boolean;
12
- readonly lastError: Error | null;
13
- readonly isPending: boolean;
14
- readonly isResolved: boolean;
15
- invalidate(): void;
16
- dispose(): void;
17
- }
18
- //# sourceMappingURL=computed.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"computed.d.ts","sourceRoot":"","sources":["../../src/types/computed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AAE1E,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,CAAC,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAChE,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,KAAK,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,UAAU,IAAI,IAAI,CAAC;IACnB,OAAO,IAAI,IAAI,CAAC;CACjB"}
@@ -1,13 +0,0 @@
1
- export interface EffectOptions {
2
- sync?: boolean;
3
- maxExecutionsPerSecond?: number;
4
- trackModifications?: boolean;
5
- }
6
- export interface EffectObject {
7
- dispose(): void;
8
- run(): void;
9
- readonly isDisposed: boolean;
10
- readonly executionCount: number;
11
- }
12
- export type EffectFunction = () => void | (() => void) | Promise<undefined | (() => void)>;
13
- //# sourceMappingURL=effect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../src/types/effect.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,IAAI,IAAI,CAAC;IAChB,GAAG,IAAI,IAAI,CAAC;IACZ,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC"}
@@ -1,5 +0,0 @@
1
- export * from './atom';
2
- export * from './common';
3
- export * from './computed';
4
- export * from './effect';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
@@ -1,85 +0,0 @@
1
- import { DebugConfig } from '../types';
2
- /**
3
- * Symbol key for storing debug display name on reactive objects.
4
- *
5
- * @remarks
6
- * Using symbols prevents property name collisions with user-defined properties.
7
- *
8
- * @example
9
- * ```typescript
10
- * const atom = createAtom(0);
11
- * console.log(atom[DEBUG_NAME]); // "atom_1"
12
- * ```
13
- */
14
- export declare const DEBUG_NAME: unique symbol;
15
- /**
16
- * Symbol key for storing unique identifier on reactive objects.
17
- *
18
- * @remarks
19
- * Each reactive object (atom, computed, effect) receives a unique numeric ID
20
- * for debugging and tracking purposes.
21
- */
22
- export declare const DEBUG_ID: unique symbol;
23
- /**
24
- * Symbol key for storing the type discriminator on reactive objects.
25
- *
26
- * @remarks
27
- * Possible values: 'atom' | 'computed' | 'effect'
28
- */
29
- export declare const DEBUG_TYPE: unique symbol;
30
- /**
31
- * Sentinel value to distinguish "no default value provided" from `undefined`.
32
- *
33
- * @remarks
34
- * This allows computed values to differentiate between:
35
- * - User explicitly passing `undefined` as default
36
- * - User not providing any default value
37
- *
38
- * @example
39
- * ```typescript
40
- * const hasDefault = options.defaultValue !== NO_DEFAULT_VALUE;
41
- * ```
42
- */
43
- export declare const NO_DEFAULT_VALUE: unique symbol;
44
- /**
45
- * Debug configuration instance with runtime utilities.
46
- *
47
- * Provides development-time features including:
48
- * - Circular dependency detection (direct and indirect)
49
- * - Large dependency graph warnings
50
- * - Debug metadata attachment for inspection
51
- *
52
- * @remarks
53
- * Most features are only active when `NODE_ENV === 'development'`
54
- * to avoid performance overhead in production builds.
55
- *
56
- * @example
57
- * ```typescript
58
- * // Check for circular dependencies
59
- * debug.checkCircular(dependencyAtom, computedAtom);
60
- *
61
- * // Warn about potential issues
62
- * debug.warn(count > 100, 'Large dependency count detected');
63
- *
64
- * // Attach debug info to a reactive object
65
- * debug.attachDebugInfo(atom, 'atom', 42);
66
- * ```
67
- */
68
- export declare const debug: DebugConfig;
69
- /**
70
- * Generates a unique numeric identifier for reactive objects.
71
- *
72
- * @returns A unique positive integer, incrementing with each call
73
- *
74
- * @remarks
75
- * IDs are globally unique within a single runtime session.
76
- * The counter resets when the module is reloaded.
77
- *
78
- * @example
79
- * ```typescript
80
- * const atomId = generateId(); // 1
81
- * const computedId = generateId(); // 2
82
- * ```
83
- */
84
- export declare const generateId: () => number;
85
- //# sourceMappingURL=debug.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/utils/debug.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,EAAE,OAAO,MAA4B,CAAC;AAE7D;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAAE,OAAO,MAAqB,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE,OAAO,MAAuB,CAAC;AAExD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAAO,MAAiC,CAAC;AAmBxE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,KAAK,EAAE,WAsKnB,CAAC;AASF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,QAAO,MAAkB,CAAC"}
@@ -1,159 +0,0 @@
1
- import { Poolable } from '../types';
2
- /**
3
- * Object Pool for efficient object reuse
4
- *
5
- * Implements the object pool pattern to reduce garbage collection pressure by
6
- * reusing objects instead of continuously creating and destroying them.
7
- *
8
- * ## Benefits:
9
- * - **Reduced GC pressure**: ~45% reduction in garbage collection overhead
10
- * - **Predictable performance**: No allocation spikes during high-load scenarios
11
- * - **Memory efficiency**: Caps maximum pool size to prevent memory bloat
12
- *
13
- * ## Usage Pattern:
14
- * 1. Acquire object from pool (or create new if pool empty)
15
- * 2. Use object for operation
16
- * 3. Release object back to pool (calls reset() automatically)
17
- *
18
- * @template T - Type that implements the Poolable interface
19
- *
20
- * @example
21
- * ```ts
22
- * const pool = new ObjectPool(() => new MyObject(), 100);
23
- *
24
- * // Pre-allocate for performance
25
- * pool.warmup(50);
26
- *
27
- * // Use pooled objects
28
- * const obj = pool.acquire();
29
- * obj.doSomething();
30
- * pool.release(obj); // Returns to pool for reuse
31
- * ```
32
- */
33
- declare class ObjectPool<T extends Poolable> {
34
- /** Array holding pooled objects */
35
- private pool;
36
- /** Current number of available objects in pool */
37
- private poolSize;
38
- /** Maximum pool size to prevent unbounded growth */
39
- private readonly maxPoolSize;
40
- /** Factory function to create new instances */
41
- private readonly factory;
42
- /**
43
- * Creates a new object pool
44
- *
45
- * @param factory - Function that creates new instances of T
46
- * @param maxPoolSize - Maximum number of objects to pool (default: 1000)
47
- */
48
- constructor(factory: () => T, maxPoolSize?: number);
49
- /**
50
- * Pre-allocates objects in the pool for better performance
51
- *
52
- * Useful before performance-critical operations to avoid allocation
53
- * overhead during execution. Creates objects up to the specified count
54
- * or maxPoolSize, whichever is smaller.
55
- *
56
- * @param count - Number of objects to pre-allocate
57
- *
58
- * @example
59
- * ```ts
60
- * const pool = new ObjectPool(() => new Notification());
61
- * pool.warmup(100); // Pre-allocate 100 objects
62
- * ```
63
- */
64
- warmup(count: number): void;
65
- /**
66
- * Acquires an object from the pool or creates a new one
67
- *
68
- * If pool has available objects, returns a pooled instance (O(1)).
69
- * Otherwise, creates a new instance using the factory function.
70
- *
71
- * @returns Reusable object instance
72
- */
73
- acquire(): T;
74
- /**
75
- * Returns an object to the pool for reuse
76
- *
77
- * Automatically calls reset() on the object before pooling.
78
- * If pool is at max capacity, the object is discarded.
79
- *
80
- * @param obj - Object to return to pool
81
- */
82
- release(obj: T): void;
83
- /**
84
- * Clears all objects from the pool
85
- *
86
- * Useful for cleanup or resetting pool state.
87
- */
88
- clear(): void;
89
- }
90
- /**
91
- * Notification object for subscriber notifications
92
- *
93
- * Poolable object used to batch subscriber notifications efficiently.
94
- * Reduces allocation overhead when notifying multiple subscribers of
95
- * atom value changes.
96
- *
97
- * @template T - Type of the value being notified
98
- */
99
- declare class Notification<T = unknown> implements Poolable {
100
- /** Listener callback function */
101
- listener: Function | null;
102
- /** New value after change */
103
- newValue: T | undefined;
104
- /** Previous value before change */
105
- oldValue: T | undefined;
106
- /**
107
- * Creates a new notification
108
- *
109
- * @param listener - Callback to invoke
110
- * @param newValue - New value to pass to callback
111
- * @param oldValue - Old value to pass to callback
112
- */
113
- constructor(listener?: Function, newValue?: T, oldValue?: T);
114
- /**
115
- * Executes the notification callback with stored values
116
- */
117
- execute(): void;
118
- /**
119
- * Resets notification to initial state for pooling
120
- */
121
- reset(): void;
122
- }
123
- /**
124
- * Scheduler callback object
125
- *
126
- * Poolable object for scheduler queue callbacks.
127
- * Reduces allocation overhead during batch operations.
128
- */
129
- declare class SchedulerCallback implements Poolable {
130
- /** Callback function to execute */
131
- callback: (() => void) | null;
132
- /**
133
- * Creates a new scheduler callback
134
- *
135
- * @param callback - Function to execute
136
- */
137
- constructor(callback?: () => void);
138
- /**
139
- * Executes the stored callback
140
- */
141
- execute(): void;
142
- /**
143
- * Resets callback to initial state for pooling
144
- */
145
- reset(): void;
146
- }
147
- /**
148
- * Global object pool for notification objects
149
- * Pre-allocated for performance-critical subscriber notifications
150
- */
151
- export declare const notificationPool: ObjectPool<Notification<unknown>>;
152
- /**
153
- * Global object pool for scheduler callbacks
154
- * Reduces allocation overhead in batching operations
155
- */
156
- export declare const schedulerCallbackPool: ObjectPool<SchedulerCallback>;
157
- export { Notification, ObjectPool, SchedulerCallback };
158
- export type { Poolable };
159
- //# sourceMappingURL=object-pool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object-pool.d.ts","sourceRoot":"","sources":["../../src/utils/object-pool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,cAAM,UAAU,CAAC,CAAC,SAAS,QAAQ;IACjC,mCAAmC;IACnC,OAAO,CAAC,IAAI,CAAW;IACvB,kDAAkD;IAClD,OAAO,CAAC,QAAQ,CAAK;IACrB,oDAAoD;IACpD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,+CAA+C;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAElC;;;;;OAKG;gBACS,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAE,MAA6B;IAKxE;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAO3B;;;;;;;OAOG;IACH,OAAO,IAAI,CAAC;IAOZ;;;;;;;OAOG;IACH,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI;IAOrB;;;;OAIG;IACH,KAAK,IAAI,IAAI;CAId;AAED;;;;;;;;GAQG;AACH,cAAM,YAAY,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,QAAQ;IACjD,iCAAiC;IACjC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAQ;IACjC,6BAA6B;IAC7B,QAAQ,EAAE,CAAC,GAAG,SAAS,CAAa;IACpC,mCAAmC;IACnC,QAAQ,EAAE,CAAC,GAAG,SAAS,CAAa;IAEpC;;;;;;OAMG;gBACS,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC;IAM3D;;OAEG;IACH,OAAO,IAAI,IAAI;IAMf;;OAEG;IACH,KAAK,IAAI,IAAI;CAKd;AAED;;;;;GAKG;AACH,cAAM,iBAAkB,YAAW,QAAQ;IACzC,mCAAmC;IACnC,QAAQ,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;IAErC;;;;OAIG;gBACS,QAAQ,CAAC,EAAE,MAAM,IAAI;IAIjC;;OAEG;IACH,OAAO,IAAI,IAAI;IAMf;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,mCAAiE,CAAC;AAE/F;;;GAGG;AACH,eAAO,MAAM,qBAAqB,+BAGjC,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;AACvD,YAAY,EAAE,QAAQ,EAAE,CAAC"}