@but212/atom-effect 0.30.1 → 0.32.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.
- package/README.md +21 -11
- package/dist/atom-effect.min.js +1 -1
- package/dist/atom-effect.min.js.map +1 -1
- package/dist/constants.d.ts +157 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core/atom.d.ts +19 -0
- package/dist/core/atom.d.ts.map +1 -0
- package/dist/core/base.d.ts +136 -0
- package/dist/core/base.d.ts.map +1 -0
- package/dist/core/buffers.d.ts +113 -0
- package/dist/core/buffers.d.ts.map +1 -0
- package/dist/core/computed.d.ts +84 -0
- package/dist/core/computed.d.ts.map +1 -0
- package/dist/core/effect.d.ts +52 -0
- package/dist/core/effect.d.ts.map +1 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/lens.d.ts +102 -0
- package/dist/core/lens.d.ts.map +1 -0
- package/dist/core/scheduler.d.ts +145 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/tracking.d.ts +123 -0
- package/dist/core/tracking.d.ts.map +1 -0
- package/dist/errors.d.ts +163 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -510
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +1078 -913
- package/dist/index.mjs.map +1 -1
- package/dist/symbols.d.ts +30 -0
- package/dist/symbols.d.ts.map +1 -0
- package/dist/types.d.ts +259 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/debug.d.ts +20 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/type-guards.d.ts +81 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/package.json +15 -14
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The global brand symbol used for type identification across all reactive primitives.
|
|
3
|
+
*
|
|
4
|
+
* Optimization: A single consolidated symbol is used to store multiple type markers
|
|
5
|
+
* using bitwise flags. This strategy minimizes property lookup overhead and reduces
|
|
6
|
+
* the overall object size by avoiding multiple type-specific properties.
|
|
7
|
+
*
|
|
8
|
+
* When to use:
|
|
9
|
+
* - To access the internal type metadata of a reactive node.
|
|
10
|
+
* - To implement custom branded objects that need to integrate with the reactive system.
|
|
11
|
+
*/
|
|
12
|
+
export declare const BRAND: unique symbol;
|
|
13
|
+
/**
|
|
14
|
+
* A collection of bitwise flags used for precise type discrimination.
|
|
15
|
+
*
|
|
16
|
+
* When to use:
|
|
17
|
+
* - To identify the specific category of a reactive node (e.g., Atom, Computed, Effect).
|
|
18
|
+
* - To verify the capabilities of a node (e.g., checking if it is writable).
|
|
19
|
+
*/
|
|
20
|
+
export declare const BrandFlags: {
|
|
21
|
+
/** Indicates that the primitive is an atom (either Readonly or Writable). */
|
|
22
|
+
readonly Atom: number;
|
|
23
|
+
/** Indicates that the primitive supports write operations, such as `.set()` or `.update()`. */
|
|
24
|
+
readonly Writable: number;
|
|
25
|
+
/** Indicates that the primitive is a computed value with dependency tracking logic. */
|
|
26
|
+
readonly Computed: number;
|
|
27
|
+
/** Indicates that the primitive is an effect handle. */
|
|
28
|
+
readonly Effect: number;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=symbols.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../src/symbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,EAAE,OAAO,MAAwC,CAAC;AAEpE;;;;;;GAMG;AACH,eAAO,MAAM,UAAU;IACrB,6EAA6E;;IAE7E,+FAA+F;;IAE/F,uFAAuF;;IAEvF,wDAAwD;;CAEhD,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { Equal, If, Merge, Prettify } from '@but212/atom-effect-utils';
|
|
2
|
+
import { AsyncState } from './constants';
|
|
3
|
+
import { BRAND } from './symbols';
|
|
4
|
+
export type { Equal, If, Merge, Prettify };
|
|
5
|
+
/**
|
|
6
|
+
* Logic: Dependency Value Extraction
|
|
7
|
+
* Extracts the inner value type `V` from a `Dependency<V>`.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export type UnboxDependency<D> = D extends Dependency<infer V> ? V : never;
|
|
11
|
+
/**
|
|
12
|
+
* Logic: Safe Object Merging
|
|
13
|
+
* Merges a union of dependency values into a single object.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export type MergedDependencyValue<T extends readonly unknown[]> = Merge<UnboxDependency<T[number]>>;
|
|
17
|
+
/** A unique monotonic identifier for reactive dependencies. */
|
|
18
|
+
export type DependencyId = number;
|
|
19
|
+
/**
|
|
20
|
+
* Interface for objects requiring explicit resource release (timers, observers, listeners).
|
|
21
|
+
*/
|
|
22
|
+
export interface Disposable {
|
|
23
|
+
/**
|
|
24
|
+
* Releases internal resources and detaches from the reactive graph.
|
|
25
|
+
*/
|
|
26
|
+
dispose(): void;
|
|
27
|
+
}
|
|
28
|
+
/** Represents the possible states of an asynchronous reactive node. */
|
|
29
|
+
export type AsyncStateType = (typeof AsyncState)[keyof typeof AsyncState];
|
|
30
|
+
/** Configuration for initializing an atom. */
|
|
31
|
+
export interface AtomOptions<T = unknown> {
|
|
32
|
+
/** Identifier for debugger and devtools. */
|
|
33
|
+
name?: string;
|
|
34
|
+
/**
|
|
35
|
+
* When true, updates bypass the scheduler and notify subscribers immediately.
|
|
36
|
+
* Caution: Can lead to inconsistent states if multiple synchronous updates depend on each other.
|
|
37
|
+
*/
|
|
38
|
+
sync?: boolean;
|
|
39
|
+
/** Custom comparator to prevent unnecessary updates if the value is structurally identical. */
|
|
40
|
+
equal?: (a: T, b: T) => boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Internal contract for dependency tracking and re-execution.
|
|
44
|
+
*
|
|
45
|
+
* Optimization: Monomorphic Access
|
|
46
|
+
* All properties are non-optional to ensure V8 optimizes property access
|
|
47
|
+
* during high-frequency graph traversals.
|
|
48
|
+
*
|
|
49
|
+
* Constraint: Managed State
|
|
50
|
+
* The `version`, `flags`, and `_lastSeenEpoch` fields are internal engine
|
|
51
|
+
* state and must not be modified by external logic.
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export interface Dependency<T = unknown> {
|
|
56
|
+
/** @internal */
|
|
57
|
+
readonly [BRAND]?: number;
|
|
58
|
+
/** Unique engine-level ID. */
|
|
59
|
+
readonly id: DependencyId;
|
|
60
|
+
/** Monotonic update counter used for drift detection. */
|
|
61
|
+
version: number;
|
|
62
|
+
/** State bitmask defined in `constants.ts`. */
|
|
63
|
+
flags: number;
|
|
64
|
+
/** Used by the scheduler to identify if a node was visited in the current epoch. */
|
|
65
|
+
_lastSeenEpoch: number;
|
|
66
|
+
/** Type discriminator for fast-path checks. */
|
|
67
|
+
readonly isComputed: boolean;
|
|
68
|
+
/** Error state flag. */
|
|
69
|
+
readonly hasError: boolean;
|
|
70
|
+
/** Engine-level subscription method. */
|
|
71
|
+
subscribe(listener: ((newValue?: T, oldValue?: T) => void) | Subscriber): () => void;
|
|
72
|
+
/** Non-reactive read. */
|
|
73
|
+
peek(): T;
|
|
74
|
+
/** Current value. */
|
|
75
|
+
readonly value: T;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A read-only reactive container.
|
|
79
|
+
*
|
|
80
|
+
* When to use:
|
|
81
|
+
* - To expose state while preventing external mutation (Unidirectional Data Flow).
|
|
82
|
+
* - To serve as a base for computed or derived values.
|
|
83
|
+
*/
|
|
84
|
+
export interface ReadonlyAtom<T = unknown> extends Dependency<T>, Disposable {
|
|
85
|
+
/** Returns the active subscriber count for diagnostic purposes. */
|
|
86
|
+
subscriberCount(): number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A reactive container supporting read and write operations.
|
|
90
|
+
*
|
|
91
|
+
* When to use:
|
|
92
|
+
* - As the primary source of truth for application state.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const count = atom(0);
|
|
97
|
+
* count.value++; // Triggers downstream updates.
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export interface WritableAtom<T = unknown> extends ReadonlyAtom<T> {
|
|
101
|
+
/** Setting the value triggers a notification cycle for all dependents. */
|
|
102
|
+
value: T;
|
|
103
|
+
}
|
|
104
|
+
/** Configuration for derived computed atoms. */
|
|
105
|
+
export interface ComputedOptions<T = unknown> {
|
|
106
|
+
/** Identifier for debugging. */
|
|
107
|
+
name?: string;
|
|
108
|
+
/** Comparator to prune updates if the computed result hasn't changed. */
|
|
109
|
+
equal?: (a: T, b: T) => boolean;
|
|
110
|
+
/** Value returned before the first computation completes. */
|
|
111
|
+
defaultValue?: T;
|
|
112
|
+
/** When true, computation only runs when the `.value` property is accessed. */
|
|
113
|
+
lazy?: boolean;
|
|
114
|
+
/** Error boundary for the computation logic. */
|
|
115
|
+
onError?: (error: Error) => void;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A derived reactive value resolving synchronously or asynchronously.
|
|
119
|
+
*
|
|
120
|
+
* When to use:
|
|
121
|
+
* - To encapsulate business logic that depends on other atoms.
|
|
122
|
+
* - To handle asynchronous data fetching with built-in status tracking.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const fullName = computed(() => `${firstName.value} ${lastName.value}`);
|
|
127
|
+
* console.log(fullName.value);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export interface ComputedAtom<T = unknown> extends ReadonlyAtom<T> {
|
|
131
|
+
/** @internal */
|
|
132
|
+
readonly [BRAND]?: number;
|
|
133
|
+
/** Current async status (idle, pending, resolved, rejected). */
|
|
134
|
+
readonly state: AsyncStateType;
|
|
135
|
+
/** True if the last computation threw an error. */
|
|
136
|
+
readonly hasError: boolean;
|
|
137
|
+
/** The most recent error encountered. */
|
|
138
|
+
readonly lastError: Error | null;
|
|
139
|
+
/** True during async execution. */
|
|
140
|
+
readonly isPending: boolean;
|
|
141
|
+
/** True if at least one successful resolution has occurred. */
|
|
142
|
+
readonly isResolved: boolean;
|
|
143
|
+
/** True if the current value is valid (resolved and no active error). */
|
|
144
|
+
readonly isValid: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Aggregate list of errors from the last evaluation cycle.
|
|
147
|
+
* Optimization: Shared with `EMPTY_ERROR_ARRAY` when no errors exist.
|
|
148
|
+
*/
|
|
149
|
+
readonly errors: readonly Error[];
|
|
150
|
+
/**
|
|
151
|
+
* Manually flags the computation as dirty.
|
|
152
|
+
* When to use: When external, non-reactive state influences the result.
|
|
153
|
+
*/
|
|
154
|
+
invalidate(): void;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Contract for nodes that can be scheduled for execution.
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
export interface Subscriber {
|
|
161
|
+
/** Invoked by the scheduler to perform the node's update logic. */
|
|
162
|
+
execute(): void;
|
|
163
|
+
}
|
|
164
|
+
/** Cleanup callback for effects. */
|
|
165
|
+
export type EffectCleanup = () => void;
|
|
166
|
+
/**
|
|
167
|
+
* Execution logic for a reactive effect.
|
|
168
|
+
* Supports async execution and optional teardown logic.
|
|
169
|
+
*/
|
|
170
|
+
export type EffectFunction = () => (void | EffectCleanup) | Promise<void | EffectCleanup>;
|
|
171
|
+
/** Configuration for reactive side-effects. */
|
|
172
|
+
export interface EffectOptions {
|
|
173
|
+
/** Identifier for diagnostics. */
|
|
174
|
+
name?: string;
|
|
175
|
+
/** When true, runs immediately upon creation. */
|
|
176
|
+
sync?: boolean;
|
|
177
|
+
/** Reason: Protection against runaway recursive loops. */
|
|
178
|
+
maxExecutionsPerSecond?: number;
|
|
179
|
+
/** Reason: Protection against circular dependencies in a single flush. */
|
|
180
|
+
maxExecutionsPerFlush?: number;
|
|
181
|
+
/** Error handler for the effect logic and its cleanup. */
|
|
182
|
+
onError?: (error: unknown) => void;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Handle for a managed reactive effect.
|
|
186
|
+
*/
|
|
187
|
+
export interface EffectObject extends Disposable {
|
|
188
|
+
/** @internal */
|
|
189
|
+
readonly [BRAND]?: number;
|
|
190
|
+
/** Manually triggers the effect. */
|
|
191
|
+
run(): void;
|
|
192
|
+
/** True if the effect is no longer active. */
|
|
193
|
+
readonly isDisposed: boolean;
|
|
194
|
+
/** Total execution count since creation. */
|
|
195
|
+
readonly executionCount: number;
|
|
196
|
+
/** True while the effect function is running. */
|
|
197
|
+
readonly isExecuting: boolean;
|
|
198
|
+
}
|
|
199
|
+
/** Diagnostic metrics for memory and resource management. @internal */
|
|
200
|
+
export interface PoolStats {
|
|
201
|
+
acquired: number;
|
|
202
|
+
released: number;
|
|
203
|
+
rejected: {
|
|
204
|
+
frozen: number;
|
|
205
|
+
tooLarge: number;
|
|
206
|
+
poolFull: number;
|
|
207
|
+
};
|
|
208
|
+
leaked: number;
|
|
209
|
+
poolSize: number;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Internal interface for engine instrumentation and debugging.
|
|
213
|
+
* @internal
|
|
214
|
+
*/
|
|
215
|
+
export interface DebugConfig {
|
|
216
|
+
/** Master toggle for diagnostic features. */
|
|
217
|
+
enabled: boolean;
|
|
218
|
+
/** Toggle for infinite loop detection. */
|
|
219
|
+
warnInfiniteLoop: boolean;
|
|
220
|
+
/** Enables full graph traversal tracking (Performance impact: High). */
|
|
221
|
+
trackGraph: boolean;
|
|
222
|
+
/** Internal logger. */
|
|
223
|
+
warn(condition: boolean, message: string): void;
|
|
224
|
+
/** Instruments objects with metadata for devtools. */
|
|
225
|
+
attachDebugInfo(obj: object, type: string, id: number, customName?: string): void;
|
|
226
|
+
/** Resolves human-readable names for diagnostic messages. */
|
|
227
|
+
getDebugName(obj: object | null | undefined): string | undefined;
|
|
228
|
+
/** Identifies the internal node type. */
|
|
229
|
+
getDebugType(obj: object | null | undefined): string | undefined;
|
|
230
|
+
/** Records update frequency for loop detection. */
|
|
231
|
+
trackUpdate(id: DependencyId, name?: string): void;
|
|
232
|
+
/** Registers nodes for global graph snapshots. */
|
|
233
|
+
registerNode(node: object & {
|
|
234
|
+
id: DependencyId;
|
|
235
|
+
}): void;
|
|
236
|
+
/** Records evaluation failures during dirty checks. */
|
|
237
|
+
trackEvaluationFailure(id: DependencyId): void;
|
|
238
|
+
/** Generates a JSON snapshot of the dependency graph. */
|
|
239
|
+
dumpGraph(): Record<string, unknown>[];
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Global configuration parameters for the Scheduler.
|
|
243
|
+
* @internal
|
|
244
|
+
*/
|
|
245
|
+
export interface SchedulerConfig {
|
|
246
|
+
/** Prevents infinite loops or runaway effects from freezing the main thread. */
|
|
247
|
+
MAX_EXECUTIONS_PER_SECOND: number;
|
|
248
|
+
/** Detects and stops circular dependencies within a single microtask. */
|
|
249
|
+
MAX_EXECUTIONS_PER_EFFECT: number;
|
|
250
|
+
/** Limits the total workload per flush to maintain frame-rate stability. */
|
|
251
|
+
MAX_EXECUTIONS_PER_FLUSH: number;
|
|
252
|
+
/** Safety break for the drain-loop to prevent stack overflows or infinite flushing. */
|
|
253
|
+
MAX_FLUSH_ITERATIONS: number;
|
|
254
|
+
/** Ensures a minimum number of iterations are processed to allow for nested batched updates. */
|
|
255
|
+
MIN_FLUSH_ITERATIONS: number;
|
|
256
|
+
/** Threshold for shrinking the internal batch queue to release memory back to the heap. */
|
|
257
|
+
BATCH_QUEUE_SHRINK_THRESHOLD: number;
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"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F,6DAA6D;IAC7D,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IACjE,yCAAyC;IACzC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IACjE,mDAAmD;IACnD,WAAW,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnD,kDAAkD;IAClD,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,EAAE,EAAE,YAAY,CAAA;KAAE,GAAG,IAAI,CAAC;IACxD,uDAAuD;IACvD,sBAAsB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAAC;IAC/C,yDAAyD;IACzD,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;CACxC;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,yBAAyB,EAAE,MAAM,CAAC;IAClC,yEAAyE;IACzE,yBAAyB,EAAE,MAAM,CAAC;IAClC,4EAA4E;IAC5E,wBAAwB,EAAE,MAAM,CAAC;IACjC,uFAAuF;IACvF,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gGAAgG;IAChG,oBAAoB,EAAE,MAAM,CAAC;IAC7B,2FAA2F;IAC3F,4BAA4B,EAAE,MAAM,CAAC;CACtC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DebugConfig, DependencyId } from '../types';
|
|
2
|
+
/** Sentinel value used to distinguish between 'undefined' and 'not set'. */
|
|
3
|
+
export declare const NO_DEFAULT_VALUE: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* Global diagnostic hub.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { debug } from '@but212/atom-effect';
|
|
10
|
+
*
|
|
11
|
+
* // View all active nodes in the console
|
|
12
|
+
* console.table(debug.dumpGraph());
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const debug: DebugConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Generates an internal unique ID for a reactive node.
|
|
18
|
+
*/
|
|
19
|
+
export declare const generateId: () => DependencyId;
|
|
20
|
+
//# sourceMappingURL=debug.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/utils/debug.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIzD,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,eAAsC,CAAC;AAkPpE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,EAAE,WAAqE,CAAC;AAK1F;;GAEG;AACH,eAAO,MAAM,UAAU,QAAO,YAAwC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Dependency, MergedDependencyValue } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Merges the values of multiple object-based atoms into a single object.
|
|
4
|
+
* @internal
|
|
5
|
+
*
|
|
6
|
+
* @param atoms - List of atoms to merge.
|
|
7
|
+
* @param peek - If true, uses .peek() instead of .value to avoid reactive tracking.
|
|
8
|
+
* @returns A single object containing all properties from the input atoms.
|
|
9
|
+
*/
|
|
10
|
+
export declare function mergeAtomValues<T extends Dependency<unknown>[]>(atoms: T, peek?: boolean): MergedDependencyValue<T>;
|
|
11
|
+
export { debug, NO_DEFAULT_VALUE } from './debug';
|
|
12
|
+
export { isAtom, isComputed, isEffect, isPromise, isWritable } from './type-guards';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEjE;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,EAC7D,KAAK,EAAE,CAAC,EACR,IAAI,UAAQ,GACX,qBAAqB,CAAC,CAAC,CAAC,CAW1B;AAED,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isPromise } from '@but212/atom-effect-utils';
|
|
2
|
+
import { ComputedAtom, EffectObject, ReadonlyAtom, WritableAtom } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Determines whether a value is a ReadonlyAtom.
|
|
5
|
+
*
|
|
6
|
+
* When to use:
|
|
7
|
+
* - To validate user input in APIs that expect reactive atoms.
|
|
8
|
+
* - To differentiate between raw values and reactive containers.
|
|
9
|
+
*
|
|
10
|
+
* @param obj - The value to check.
|
|
11
|
+
* @returns True if the value is an atom.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { isAtom } from '@but212/atom-effect';
|
|
16
|
+
*
|
|
17
|
+
* if (isAtom(maybeAtom)) {
|
|
18
|
+
* console.log(maybeAtom.value);
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function isAtom(obj: unknown): obj is ReadonlyAtom;
|
|
23
|
+
/**
|
|
24
|
+
* Determines whether a value is a WritableAtom.
|
|
25
|
+
*
|
|
26
|
+
* When to use:
|
|
27
|
+
* - To verify if an atom can be modified via `.set()` or `.update()` before attempting the operation.
|
|
28
|
+
*
|
|
29
|
+
* @param obj - The value to check.
|
|
30
|
+
* @returns True if the value is a writable atom.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { isWritable } from '@but212/atom-effect';
|
|
35
|
+
*
|
|
36
|
+
* if (isWritable(maybeAtom)) {
|
|
37
|
+
* maybeAtom.value = 123;
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function isWritable(obj: unknown): obj is WritableAtom;
|
|
42
|
+
/**
|
|
43
|
+
* Determines whether a value is a ComputedAtom.
|
|
44
|
+
*
|
|
45
|
+
* When to use:
|
|
46
|
+
* - To identify derived state containers that may have underlying dependencies.
|
|
47
|
+
*
|
|
48
|
+
* @param obj - The value to check.
|
|
49
|
+
* @returns True if the value is a computed atom.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { isComputed } from '@but212/atom-effect';
|
|
54
|
+
*
|
|
55
|
+
* if (isComputed(maybeAtom)) {
|
|
56
|
+
* console.log('This atom is a derived value.');
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function isComputed(obj: unknown): obj is ComputedAtom;
|
|
61
|
+
/**
|
|
62
|
+
* Determines whether a value is an EffectObject.
|
|
63
|
+
*
|
|
64
|
+
* When to use:
|
|
65
|
+
* - To validate objects that manage reactive side-effects.
|
|
66
|
+
*
|
|
67
|
+
* @param obj - The value to check.
|
|
68
|
+
* @returns True if the value is an effect handle.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { isEffect } from '@but212/atom-effect';
|
|
73
|
+
*
|
|
74
|
+
* if (isEffect(maybeEffect)) {
|
|
75
|
+
* maybeEffect.dispose();
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function isEffect(obj: unknown): obj is EffectObject;
|
|
80
|
+
export { isPromise };
|
|
81
|
+
//# sourceMappingURL=type-guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA4BtF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,YAAY,CAExD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,YAAY,CAE5D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,YAAY,CAE5D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,YAAY,CAE1D;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@but212/atom-effect",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.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
6
|
"main": "./dist/index.cjs",
|
|
@@ -39,16 +39,18 @@
|
|
|
39
39
|
"directory": "packages/core"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/
|
|
43
|
-
"@
|
|
44
|
-
"@vitest/
|
|
45
|
-
"@vitest/
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"tinybench": "^6.0.
|
|
49
|
-
"vite": "^8.0.
|
|
42
|
+
"@types/node": "^25.6.2",
|
|
43
|
+
"@vitest/browser": "^4.1.5",
|
|
44
|
+
"@vitest/browser-playwright": "^4.1.5",
|
|
45
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
46
|
+
"@vitest/ui": "^4.1.5",
|
|
47
|
+
"playwright": "^1.59.1",
|
|
48
|
+
"tinybench": "^6.0.1",
|
|
49
|
+
"vite": "^8.0.11",
|
|
50
50
|
"vite-plugin-dts": "^4.5.4",
|
|
51
|
-
"vitest": "^4.1.
|
|
51
|
+
"vitest": "^4.1.5",
|
|
52
|
+
"@but212/atom-effect-configs": "0.0.0",
|
|
53
|
+
"@but212/atom-effect-utils": "0.0.0"
|
|
52
54
|
},
|
|
53
55
|
"scripts": {
|
|
54
56
|
"build": "vite build",
|
|
@@ -66,10 +68,9 @@
|
|
|
66
68
|
"bench": "vitest bench --config vitest.bench.config.ts",
|
|
67
69
|
"bench:micro": "pnpm run bench __benchmarks__/micro",
|
|
68
70
|
"bench:macro": "pnpm run bench __benchmarks__/macro",
|
|
69
|
-
"bench:
|
|
70
|
-
"bench:computed": "pnpm run bench __benchmarks__/micro/computed.bench",
|
|
71
|
-
"bench:effect": "pnpm run bench __benchmarks__/micro/effect.bench",
|
|
71
|
+
"bench:state": "pnpm run bench __benchmarks__/state",
|
|
72
72
|
"bench:realistic": "pnpm run bench __benchmarks__/realistic",
|
|
73
|
-
"bench:
|
|
73
|
+
"bench:scheduler": "pnpm run bench __benchmarks__/micro/scheduler.bench.ts",
|
|
74
|
+
"bench:all": "pnpm run bench"
|
|
74
75
|
}
|
|
75
76
|
}
|