mutts 1.0.4 → 1.0.6
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 +2 -1
- package/dist/chunks/{_tslib-Mzh1rNsX.esm.js → _tslib-MCKDzsSq.esm.js} +2 -2
- package/dist/chunks/_tslib-MCKDzsSq.esm.js.map +1 -0
- package/dist/chunks/decorator-BGILvPtN.esm.js +627 -0
- package/dist/chunks/decorator-BGILvPtN.esm.js.map +1 -0
- package/dist/chunks/decorator-BQ2eBTCj.js +651 -0
- package/dist/chunks/decorator-BQ2eBTCj.js.map +1 -0
- package/dist/chunks/{index-GRBSx0mB.js → index-CDCOjzTy.js} +543 -495
- package/dist/chunks/index-CDCOjzTy.js.map +1 -0
- package/dist/chunks/{index-79Kk8D6e.esm.js → index-DiP0RXoZ.esm.js} +452 -404
- package/dist/chunks/index-DiP0RXoZ.esm.js.map +1 -0
- package/dist/decorator.d.ts +3 -3
- package/dist/decorator.esm.js +1 -1
- package/dist/decorator.js +1 -1
- package/dist/destroyable.esm.js +4 -4
- package/dist/destroyable.esm.js.map +1 -1
- package/dist/destroyable.js +4 -4
- package/dist/destroyable.js.map +1 -1
- package/dist/devtools/panel.js.map +1 -1
- package/dist/eventful.esm.js +1 -1
- package/dist/index.esm.js +48 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +50 -4
- package/dist/index.js.map +1 -1
- package/dist/mutts.umd.js +1 -1
- package/dist/mutts.umd.js.map +1 -1
- package/dist/mutts.umd.min.js +1 -1
- package/dist/mutts.umd.min.js.map +1 -1
- package/dist/reactive.d.ts +54 -1
- package/dist/reactive.esm.js +3 -3
- package/dist/reactive.js +6 -4
- package/dist/reactive.js.map +1 -1
- package/dist/std-decorators.d.ts +1 -1
- package/dist/std-decorators.esm.js +10 -10
- package/dist/std-decorators.esm.js.map +1 -1
- package/dist/std-decorators.js +10 -10
- package/dist/std-decorators.js.map +1 -1
- package/docs/ai/manual.md +14 -95
- package/docs/reactive/advanced.md +6 -107
- package/docs/reactive/core.md +16 -16
- package/docs/reactive/debugging.md +158 -0
- package/docs/reactive.md +8 -0
- package/package.json +16 -66
- package/src/decorator.ts +11 -9
- package/src/destroyable.ts +5 -5
- package/src/index.ts +46 -0
- package/src/reactive/array.ts +3 -5
- package/src/reactive/change.ts +7 -3
- package/src/reactive/debug.ts +1 -1
- package/src/reactive/deep-touch.ts +1 -1
- package/src/reactive/deep-watch.ts +1 -1
- package/src/reactive/effect-context.ts +2 -2
- package/src/reactive/effects.ts +114 -17
- package/src/reactive/index.ts +3 -2
- package/src/reactive/interface.ts +10 -9
- package/src/reactive/map.ts +6 -6
- package/src/reactive/mapped.ts +2 -3
- package/src/reactive/memoize.ts +77 -31
- package/src/reactive/project.ts +103 -6
- package/src/reactive/proxy.ts +4 -4
- package/src/reactive/registry.ts +67 -0
- package/src/reactive/set.ts +6 -6
- package/src/reactive/tracking.ts +12 -41
- package/src/reactive/types.ts +59 -0
- package/src/reactive/zone.ts +1 -1
- package/src/std-decorators.ts +10 -10
- package/src/utils.ts +141 -0
- package/dist/chunks/_tslib-Mzh1rNsX.esm.js.map +0 -1
- package/dist/chunks/decorator-DLvrD0UF.js +0 -265
- package/dist/chunks/decorator-DLvrD0UF.js.map +0 -1
- package/dist/chunks/decorator-DqiszP7i.esm.js +0 -253
- package/dist/chunks/decorator-DqiszP7i.esm.js.map +0 -1
- package/dist/chunks/index-79Kk8D6e.esm.js.map +0 -1
- package/dist/chunks/index-GRBSx0mB.js.map +0 -1
- /package/{src/reactive/project.project.md → docs/reactive/project.md} +0 -0
package/dist/reactive.d.ts
CHANGED
|
@@ -107,6 +107,16 @@ type State = {
|
|
|
107
107
|
evolution: Evolution;
|
|
108
108
|
next: State;
|
|
109
109
|
} | {};
|
|
110
|
+
/**
|
|
111
|
+
* Context for a running projection item effect
|
|
112
|
+
*/
|
|
113
|
+
interface ProjectionContext {
|
|
114
|
+
source: any;
|
|
115
|
+
key?: any;
|
|
116
|
+
target: any;
|
|
117
|
+
depth: number;
|
|
118
|
+
parent?: ProjectionContext;
|
|
119
|
+
}
|
|
110
120
|
/**
|
|
111
121
|
* Structured error codes for machine-readable diagnosis
|
|
112
122
|
*/
|
|
@@ -196,12 +206,38 @@ declare const options: {
|
|
|
196
206
|
* @default 100
|
|
197
207
|
*/
|
|
198
208
|
maxEffectChain: number;
|
|
209
|
+
/**
|
|
210
|
+
* Maximum number of times an effect can be triggered by the same cause in a single batch
|
|
211
|
+
* Used to detect aggressive re-computation or infinite loops
|
|
212
|
+
* @default 10
|
|
213
|
+
*/
|
|
214
|
+
maxTriggerPerBatch: number;
|
|
199
215
|
/**
|
|
200
216
|
* Debug purpose: maximum effect reaction (like call stack max depth)
|
|
201
217
|
* Used to prevent infinite loops
|
|
202
218
|
* @default 'throw'
|
|
203
219
|
*/
|
|
204
220
|
maxEffectReaction: "throw" | "debug" | "warn";
|
|
221
|
+
/**
|
|
222
|
+
* Callback called when a memoization discrepancy is detected (debug only)
|
|
223
|
+
* When defined, memoized functions will run a second time (untracked) to verify consistency.
|
|
224
|
+
* If the untracked run returns a different value than the cached one, this callback is triggered.
|
|
225
|
+
*
|
|
226
|
+
* This is the primary tool for detecting missing reactive dependencies in computed values.
|
|
227
|
+
*
|
|
228
|
+
* @param cached - The value currently in the memoization cache
|
|
229
|
+
* @param fresh - The value obtained by re-running the function untracked
|
|
230
|
+
* @param fn - The memoized function itself
|
|
231
|
+
* @param args - Arguments passed to the function
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* reactiveOptions.onMemoizationDiscrepancy = (cached, fresh, fn, args) => {
|
|
236
|
+
* throw new Error(`Memoization discrepancy in ${fn.name}!`);
|
|
237
|
+
* };
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
onMemoizationDiscrepancy: ((cached: any, fresh: any, fn: Function, args: any[], cause: "calculation" | "comparison") => void) | undefined;
|
|
205
241
|
/**
|
|
206
242
|
* How to handle cycles detected in effect batches
|
|
207
243
|
* - 'throw': Throw an error with cycle information (default, recommended for development)
|
|
@@ -211,6 +247,11 @@ declare const options: {
|
|
|
211
247
|
* @default 'throw'
|
|
212
248
|
*/
|
|
213
249
|
cycleHandling: "throw" | "warn" | "break" | "strict";
|
|
250
|
+
/**
|
|
251
|
+
* Internal flag used by memoization discrepancy detector to avoid counting calls in tests
|
|
252
|
+
* @warning Do not modify this flag manually, this flag is given by the engine
|
|
253
|
+
*/
|
|
254
|
+
isVerificationRun: boolean;
|
|
214
255
|
/**
|
|
215
256
|
* Maximum depth for deep watching traversal
|
|
216
257
|
* Used to prevent infinite recursion in circular references
|
|
@@ -406,6 +447,14 @@ declare function getActiveEffect(): ScopedCallback;
|
|
|
406
447
|
|
|
407
448
|
type EffectTracking = (obj: any, evolution: Evolution, prop: any) => void;
|
|
408
449
|
|
|
450
|
+
interface ActivationRecord {
|
|
451
|
+
effect: ScopedCallback;
|
|
452
|
+
obj: any;
|
|
453
|
+
evolution: Evolution;
|
|
454
|
+
prop: any;
|
|
455
|
+
batchId: number;
|
|
456
|
+
}
|
|
457
|
+
declare function getActivationLog(): Omit<ActivationRecord, "batchId">[];
|
|
409
458
|
/**
|
|
410
459
|
* Registers a debug callback that is called when the current effect is triggered by a dependency change
|
|
411
460
|
*
|
|
@@ -674,6 +723,10 @@ type Register<T, K extends PropertyKey = PropertyKey> = RegisterClass<T, K> & T[
|
|
|
674
723
|
declare const Register: new <T, K extends PropertyKey = PropertyKey>(keyFn: KeyFunction<T, K>, initial?: Iterable<T>) => Register<T, K>;
|
|
675
724
|
declare function register<T, K extends PropertyKey = PropertyKey>(keyFn: KeyFunction<T, K>, initial?: Iterable<T>): Register<T, K>;
|
|
676
725
|
|
|
726
|
+
/**
|
|
727
|
+
* Returns the projection context of the currently running effect, if any.
|
|
728
|
+
*/
|
|
729
|
+
declare function getActiveProjection(): ProjectionContext | undefined;
|
|
677
730
|
type ProjectOldValue<Target> = Target extends readonly (infer Item)[] ? Item : Target extends Map<any, infer Item> ? Item : Target extends Record<PropertyKey, infer Item> ? Item : unknown;
|
|
678
731
|
type ProjectAccess<SourceValue, Key, SourceType, Target> = {
|
|
679
732
|
readonly key: Key;
|
|
@@ -853,5 +906,5 @@ declare function isZoneEnabled(): boolean;
|
|
|
853
906
|
*/
|
|
854
907
|
declare const profileInfo: any;
|
|
855
908
|
|
|
856
|
-
export { ReactiveBase, ReactiveError, ReadOnlyError, Register, addBatchCleanup, atomic, batch, biDi, buildReactivityGraph, cleanedBy, cleanup, deepWatch, defer, derived, effect, enableDevTools, getActiveEffect, getState, immutables, isDevtoolsEnabled, isNonReactive, isReactive, isZoneEnabled, mapped, memoize, organize, organized, profileInfo, project, reactive, options as reactiveOptions, reduced, register, registerEffectForDebug, registerNativeReactivity, registerObjectForDebug, root, setEffectName, setObjectName, setZoneEnabled, touched, touched1, trackEffect, unreactive, untracked, unwrap, watch };
|
|
909
|
+
export { ReactiveBase, ReactiveError, ReadOnlyError, Register, addBatchCleanup, atomic, batch, biDi, buildReactivityGraph, cleanedBy, cleanup, deepWatch, defer, derived, effect, enableDevTools, getActivationLog, getActiveEffect, getActiveProjection, getState, immutables, isDevtoolsEnabled, isNonReactive, isReactive, isZoneEnabled, mapped, memoize, organize, organized, profileInfo, project, reactive, options as reactiveOptions, reduced, register, registerEffectForDebug, registerNativeReactivity, registerObjectForDebug, root, setEffectName, setObjectName, setZoneEnabled, touched, touched1, trackEffect, unreactive, untracked, unwrap, watch };
|
|
857
910
|
export type { DependencyAccess, DependencyFunction, Evolution, Memoizable, ReactivityGraph, ScopedCallback };
|
package/dist/reactive.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export { R as ReactiveBase, b as ReadOnlyError, c as Register, d as addBatchCleanup, e as atomic, f as batch, g as biDi, h as buildReactivityGraph, i as cleanedBy, j as cleanup, k as deepWatch, l as defer, m as derived, n as effect, o as enableDevTools, p as getActivationLog, q as getActiveEffect, r as getActiveProjection, s as getState, t as immutables, u as isDevtoolsEnabled, v as isNonReactive, w as isReactive, x as isZoneEnabled, y as mapped, z as memoize, B as organize, C as organized, D as profileInfo, E as project, F as reactive, G as reduced, H as register, J as registerEffectForDebug, K as registerNativeReactivity, L as registerObjectForDebug, M as root, N as setEffectName, O as setObjectName, P as setZoneEnabled, Q as touched, S as touched1, T as trackEffect, U as unreactive, V as untracked, W as unwrap, X as watch } from './chunks/index-DiP0RXoZ.esm.js';
|
|
2
|
+
export { R as ReactiveError, o as reactiveOptions } from './chunks/decorator-BGILvPtN.esm.js';
|
|
3
3
|
import './indexable.esm.js';
|
|
4
|
-
import './chunks/_tslib-
|
|
4
|
+
import './chunks/_tslib-MCKDzsSq.esm.js';
|
|
5
5
|
//# sourceMappingURL=reactive.esm.js.map
|
package/dist/reactive.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var reactive = require('./chunks/index-
|
|
4
|
-
require('./chunks/decorator-
|
|
3
|
+
var reactive = require('./chunks/index-CDCOjzTy.js');
|
|
4
|
+
var decorator = require('./chunks/decorator-BQ2eBTCj.js');
|
|
5
5
|
require('./indexable.js');
|
|
6
6
|
require('./chunks/_tslib-BgjropY9.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
exports.ReactiveBase = reactive.ReactiveBase;
|
|
11
|
-
exports.ReactiveError = reactive.ReactiveError;
|
|
12
11
|
exports.ReadOnlyError = reactive.ReadOnlyError;
|
|
13
12
|
exports.Register = reactive.Register;
|
|
14
13
|
exports.addBatchCleanup = reactive.addBatchCleanup;
|
|
@@ -23,7 +22,9 @@ exports.defer = reactive.defer;
|
|
|
23
22
|
exports.derived = reactive.derived;
|
|
24
23
|
exports.effect = reactive.effect;
|
|
25
24
|
exports.enableDevTools = reactive.enableDevTools;
|
|
25
|
+
exports.getActivationLog = reactive.getActivationLog;
|
|
26
26
|
exports.getActiveEffect = reactive.getActiveEffect;
|
|
27
|
+
exports.getActiveProjection = reactive.getActiveProjection;
|
|
27
28
|
exports.getState = reactive.getState;
|
|
28
29
|
exports.immutables = reactive.immutables;
|
|
29
30
|
exports.isDevtoolsEnabled = reactive.isDevtoolsEnabled;
|
|
@@ -37,7 +38,6 @@ exports.organized = reactive.organized;
|
|
|
37
38
|
exports.profileInfo = reactive.profileInfo;
|
|
38
39
|
exports.project = reactive.project;
|
|
39
40
|
exports.reactive = reactive.reactive;
|
|
40
|
-
exports.reactiveOptions = reactive.options;
|
|
41
41
|
exports.reduced = reactive.reduced;
|
|
42
42
|
exports.register = reactive.register;
|
|
43
43
|
exports.registerEffectForDebug = reactive.registerEffectForDebug;
|
|
@@ -54,4 +54,6 @@ exports.unreactive = reactive.unreactive;
|
|
|
54
54
|
exports.untracked = reactive.untracked;
|
|
55
55
|
exports.unwrap = reactive.unwrap;
|
|
56
56
|
exports.watch = reactive.watch;
|
|
57
|
+
exports.ReactiveError = decorator.ReactiveError;
|
|
58
|
+
exports.reactiveOptions = decorator.options;
|
|
57
59
|
//# sourceMappingURL=reactive.js.map
|
package/dist/reactive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactive.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reactive.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/std-decorators.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LegacyPropertyDecorator, ModernGetterDecorator, ModernAccessorDecorator,
|
|
1
|
+
import { LegacyPropertyDecorator, ModernGetterDecorator, ModernAccessorDecorator, ModernMethodDecorator, LegacyClassDecorator, ModernClassDecorator, ModernSetterDecorator, GenericClassDecorator } from './decorator.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Decorator that caches the result of a getter method and only recomputes when dependencies change
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as decorator } from './chunks/decorator-
|
|
1
|
+
import { d as decorator } from './chunks/decorator-BGILvPtN.esm.js';
|
|
2
2
|
|
|
3
3
|
// In order to avoid async re-entrance, we could use zone.js or something like that.
|
|
4
4
|
const syncCalculating = [];
|
|
@@ -7,7 +7,7 @@ const syncCalculating = [];
|
|
|
7
7
|
* Prevents circular dependencies and provides automatic cache invalidation
|
|
8
8
|
*/
|
|
9
9
|
const cached = decorator({
|
|
10
|
-
getter(original, propertyKey) {
|
|
10
|
+
getter(original, _target, propertyKey) {
|
|
11
11
|
return function () {
|
|
12
12
|
const alreadyCalculating = syncCalculating.findIndex((c) => c.object === this && c.prop === propertyKey);
|
|
13
13
|
if (alreadyCalculating > -1)
|
|
@@ -70,19 +70,19 @@ function describe(descriptor) {
|
|
|
70
70
|
* Provides warning messages when deprecated items are used
|
|
71
71
|
*/
|
|
72
72
|
const deprecated = Object.assign(decorator({
|
|
73
|
-
method(original, propertyKey) {
|
|
73
|
+
method(original, _target, propertyKey) {
|
|
74
74
|
return function (...args) {
|
|
75
75
|
deprecated.warn(this, propertyKey);
|
|
76
76
|
return original.apply(this, args);
|
|
77
77
|
};
|
|
78
78
|
},
|
|
79
|
-
getter(original, propertyKey) {
|
|
79
|
+
getter(original, _target, propertyKey) {
|
|
80
80
|
return function () {
|
|
81
81
|
deprecated.warn(this, propertyKey);
|
|
82
82
|
return original.call(this);
|
|
83
83
|
};
|
|
84
84
|
},
|
|
85
|
-
setter(original, propertyKey) {
|
|
85
|
+
setter(original, _target, propertyKey) {
|
|
86
86
|
return function (value) {
|
|
87
87
|
deprecated.warn(this, propertyKey);
|
|
88
88
|
return original.call(this, value);
|
|
@@ -98,19 +98,19 @@ const deprecated = Object.assign(decorator({
|
|
|
98
98
|
},
|
|
99
99
|
default(message) {
|
|
100
100
|
return decorator({
|
|
101
|
-
method(original, propertyKey) {
|
|
101
|
+
method(original, _target, propertyKey) {
|
|
102
102
|
return function (...args) {
|
|
103
103
|
deprecated.warn(this, propertyKey, message);
|
|
104
104
|
return original.apply(this, args);
|
|
105
105
|
};
|
|
106
106
|
},
|
|
107
|
-
getter(original, propertyKey) {
|
|
107
|
+
getter(original, _target, propertyKey) {
|
|
108
108
|
return function () {
|
|
109
109
|
deprecated.warn(this, propertyKey, message);
|
|
110
110
|
return original.call(this);
|
|
111
111
|
};
|
|
112
112
|
},
|
|
113
|
-
setter(original, propertyKey) {
|
|
113
|
+
setter(original, _target, propertyKey) {
|
|
114
114
|
return function (value) {
|
|
115
115
|
deprecated.warn(this, propertyKey, message);
|
|
116
116
|
return original.call(this, value);
|
|
@@ -139,7 +139,7 @@ const deprecated = Object.assign(decorator({
|
|
|
139
139
|
*/
|
|
140
140
|
function debounce(delay) {
|
|
141
141
|
return decorator({
|
|
142
|
-
method(original, _propertyKey) {
|
|
142
|
+
method(original, _target, _propertyKey) {
|
|
143
143
|
let timeoutId = null;
|
|
144
144
|
return function (...args) {
|
|
145
145
|
// Clear existing timeout
|
|
@@ -162,7 +162,7 @@ function debounce(delay) {
|
|
|
162
162
|
*/
|
|
163
163
|
function throttle(delay) {
|
|
164
164
|
return decorator({
|
|
165
|
-
method(original, _propertyKey) {
|
|
165
|
+
method(original, _target, _propertyKey) {
|
|
166
166
|
let lastCallTime = 0;
|
|
167
167
|
let timeoutId = null;
|
|
168
168
|
return function (...args) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"std-decorators.esm.js","sources":["../src/std-decorators.ts"],"sourcesContent":["import { decorator, GenericClassDecorator } from './decorator'\n\n// In order to avoid async re-entrance, we could use zone.js or something like that.\nconst syncCalculating: { object: object; prop: PropertyKey }[] = []\n/**\n * Decorator that caches the result of a getter method and only recomputes when dependencies change\n * Prevents circular dependencies and provides automatic cache invalidation\n */\nexport const cached = decorator({\n\tgetter(original, propertyKey) {\n\t\treturn function (this: any) {\n\t\t\tconst alreadyCalculating = syncCalculating.findIndex(\n\t\t\t\t(c) => c.object === this && c.prop === propertyKey\n\t\t\t)\n\t\t\tif (alreadyCalculating > -1)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Circular dependency detected: ${syncCalculating\n\t\t\t\t\t\t.slice(alreadyCalculating)\n\t\t\t\t\t\t.map((c) => `${c.object.constructor.name}.${String(c.prop)}`)\n\t\t\t\t\t\t.join(' -> ')} -> again`\n\t\t\t\t)\n\t\t\tsyncCalculating.push({ object: this, prop: propertyKey })\n\t\t\ttry {\n\t\t\t\tconst rv = original.call(this)\n\t\t\t\tcache(this, propertyKey, rv)\n\t\t\t\treturn rv\n\t\t\t} finally {\n\t\t\t\tsyncCalculating.pop()\n\t\t\t}\n\t\t}\n\t},\n})\n\n/**\n * Checks if a property is cached (has a cached value)\n * @param object - The object to check\n * @param propertyKey - The property key to check\n * @returns True if the property has a cached value\n */\nexport function isCached(object: Object, propertyKey: PropertyKey) {\n\treturn !!Object.getOwnPropertyDescriptor(object, propertyKey)\n}\n\n/**\n * Caches a value for a property on an object\n * @param object - The object to cache the value on\n * @param propertyKey - The property key to cache\n * @param value - The value to cache\n */\nexport function cache(object: Object, propertyKey: PropertyKey, value: any) {\n\tObject.defineProperty(object, propertyKey, { value })\n}\n\n/**\n * Creates a decorator that modifies property descriptors for specified properties\n * @param descriptor - The descriptor properties to apply\n * @returns A class decorator that applies the descriptor to specified properties\n */\nexport function describe(descriptor: {\n\tenumerable?: boolean\n\tconfigurable?: boolean // Not modifiable once the property has been defined ?\n\twritable?: boolean\n}) {\n\treturn <T>(...properties: (keyof T)[]): GenericClassDecorator<T> =>\n\t\t(Base) => {\n\t\t\treturn class extends Base {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tfor (const key of properties) {\n\t\t\t\t\t\tObject.defineProperty(this, key, {\n\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptor(this, key),\n\t\t\t\t\t\t\t...descriptor,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n}\n\n/**\n * Decorator that marks methods, properties, or classes as deprecated\n * Provides warning messages when deprecated items are used\n */\nexport const deprecated = Object.assign(\n\tdecorator({\n\t\tmethod(original, propertyKey) {\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.apply(this, args)\n\t\t\t}\n\t\t},\n\t\tgetter(original, propertyKey) {\n\t\t\treturn function (this: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this)\n\t\t\t}\n\t\t},\n\t\tsetter(original, propertyKey) {\n\t\t\treturn function (this: any, value: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this, value)\n\t\t\t}\n\t\t},\n\t\tclass(original) {\n\t\t\treturn class extends original {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tdeprecated.warn(this, 'constructor')\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tdefault(message: string) {\n\t\t\treturn decorator({\n\t\t\t\tmethod(original, propertyKey) {\n\t\t\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tgetter(original, propertyKey) {\n\t\t\t\t\treturn function (this: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tsetter(original, propertyKey) {\n\t\t\t\t\treturn function (this: any, value: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this, value)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tclass(original) {\n\t\t\t\t\treturn class extends original {\n\t\t\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\t\t\tsuper(...args)\n\t\t\t\t\t\t\tdeprecated.warn(this, 'constructor', message)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t})\n\t\t},\n\t}),\n\t{\n\t\twarn: (target: any, propertyKey: PropertyKey, message?: string) => {\n\t\t\t// biome-ignore lint/suspicious/noConsole: To be overridden\n\t\t\tconsole.warn(\n\t\t\t\t`${target.constructor.name}.${String(propertyKey)} is deprecated${message ? `: ${message}` : ''}`\n\t\t\t)\n\t\t},\n\t}\n)\n\n/**\n * Creates a debounced method decorator that delays execution until after the delay period has passed\n * @param delay - The delay in milliseconds\n * @returns A method decorator that debounces method calls\n */\nexport function debounce(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _propertyKey) {\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t// Clear existing timeout\n\t\t\t\tif (timeoutId) {\n\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t}\n\n\t\t\t\t// Set new timeout\n\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\toriginal.apply(this, args)\n\t\t\t\t\ttimeoutId = null\n\t\t\t\t}, delay)\n\t\t\t}\n\t\t},\n\t})\n}\n\n/**\n * Creates a throttled method decorator that limits execution to once per delay period\n * @param delay - The delay in milliseconds\n * @returns A method decorator that throttles method calls\n */\nexport function throttle(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _propertyKey) {\n\t\t\tlet lastCallTime = 0\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tconst now = Date.now()\n\n\t\t\t\t// If enough time has passed since last call, execute immediately\n\t\t\t\tif (now - lastCallTime >= delay) {\n\t\t\t\t\t// Clear any pending timeout since we're executing now\n\t\t\t\t\tif (timeoutId) {\n\t\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}\n\t\t\t\t\tlastCallTime = now\n\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t}\n\n\t\t\t\t// Otherwise, schedule execution for when the delay period ends\n\t\t\t\tif (!timeoutId) {\n\t\t\t\t\tconst remainingTime = delay - (now - lastCallTime)\n\t\t\t\t\tconst scheduledArgs = [...args] // Capture args at scheduling time\n\t\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\t\tlastCallTime = Date.now()\n\t\t\t\t\t\toriginal.apply(this, scheduledArgs)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}, remainingTime)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t})\n}\n"],"names":[],"mappings":";;AAEA;AACA,MAAM,eAAe,GAA4C,EAAE;AACnE;;;AAGG;AACI,MAAM,MAAM,GAAG,SAAS,CAAC;IAC/B,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAA;QAC3B,OAAO,YAAA;YACN,MAAM,kBAAkB,GAAG,eAAe,CAAC,SAAS,CACnD,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAClD;YACD,IAAI,kBAAkB,GAAG,EAAE;AAC1B,gBAAA,MAAM,IAAI,KAAK,CACd,CAAA,8BAAA,EAAiC;qBAC/B,KAAK,CAAC,kBAAkB;qBACxB,GAAG,CAAC,CAAC,CAAC,KAAK,CAAA,EAAG,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA,CAAE;AAC3D,qBAAA,IAAI,CAAC,MAAM,CAAC,CAAA,SAAA,CAAW,CACzB;AACF,YAAA,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AACzD,YAAA,IAAI;gBACH,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;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BACjB,CAAC,EAAE,KAAK,CAAC;AACV,YAAA,CAAC;QACF,CAAC;AACD,KAAA,CAAC;AACH;AAEA;;;;AAIG;AACG,SAAU,QAAQ,CAAC,KAAa,EAAA;AACrC,IAAA,OAAO,SAAS,CAAC;QAChB,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAA;YAC5B,IAAI,YAAY,GAAG,CAAC;YACpB,IAAI,SAAS,GAAyC,IAAI;YAE1D,OAAO,UAAqB,GAAG,IAAW,EAAA;AACzC,gBAAA,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;;AAGtB,gBAAA,IAAI,GAAG,GAAG,YAAY,IAAI,KAAK,EAAE;;oBAEhC,IAAI,SAAS,EAAE;wBACd,YAAY,CAAC,SAAS,CAAC;wBACvB,SAAS,GAAG,IAAI;oBACjB;oBACA,YAAY,GAAG,GAAG;oBAClB,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;gBAClC;;gBAGA,IAAI,CAAC,SAAS,EAAE;oBACf,MAAM,aAAa,GAAG,KAAK,IAAI,GAAG,GAAG,YAAY,CAAC;oBAClD,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;AAC/B,oBAAA,SAAS,GAAG,UAAU,CAAC,MAAK;AAC3B,wBAAA,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE;AACzB,wBAAA,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC;wBACnC,SAAS,GAAG,IAAI;oBACjB,CAAC,EAAE,aAAa,CAAC;gBAClB;AACD,YAAA,CAAC;QACF,CAAC;AACD,KAAA,CAAC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"std-decorators.esm.js","sources":["../src/std-decorators.ts"],"sourcesContent":["import { decorator, type GenericClassDecorator } from './decorator'\n\n// In order to avoid async re-entrance, we could use zone.js or something like that.\nconst syncCalculating: { object: object; prop: PropertyKey }[] = []\n/**\n * Decorator that caches the result of a getter method and only recomputes when dependencies change\n * Prevents circular dependencies and provides automatic cache invalidation\n */\nexport const cached = decorator({\n\tgetter(original, _target, propertyKey) {\n\t\treturn function (this: any) {\n\t\t\tconst alreadyCalculating = syncCalculating.findIndex(\n\t\t\t\t(c) => c.object === this && c.prop === propertyKey\n\t\t\t)\n\t\t\tif (alreadyCalculating > -1)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Circular dependency detected: ${syncCalculating\n\t\t\t\t\t\t.slice(alreadyCalculating)\n\t\t\t\t\t\t.map((c) => `${c.object.constructor.name}.${String(c.prop)}`)\n\t\t\t\t\t\t.join(' -> ')} -> again`\n\t\t\t\t)\n\t\t\tsyncCalculating.push({ object: this, prop: propertyKey })\n\t\t\ttry {\n\t\t\t\tconst rv = original.call(this)\n\t\t\t\tcache(this, propertyKey, rv)\n\t\t\t\treturn rv\n\t\t\t} finally {\n\t\t\t\tsyncCalculating.pop()\n\t\t\t}\n\t\t}\n\t},\n})\n\n/**\n * Checks if a property is cached (has a cached value)\n * @param object - The object to check\n * @param propertyKey - The property key to check\n * @returns True if the property has a cached value\n */\nexport function isCached(object: Object, propertyKey: PropertyKey) {\n\treturn !!Object.getOwnPropertyDescriptor(object, propertyKey)\n}\n\n/**\n * Caches a value for a property on an object\n * @param object - The object to cache the value on\n * @param propertyKey - The property key to cache\n * @param value - The value to cache\n */\nexport function cache(object: Object, propertyKey: PropertyKey, value: any) {\n\tObject.defineProperty(object, propertyKey, { value })\n}\n\n/**\n * Creates a decorator that modifies property descriptors for specified properties\n * @param descriptor - The descriptor properties to apply\n * @returns A class decorator that applies the descriptor to specified properties\n */\nexport function describe(descriptor: {\n\tenumerable?: boolean\n\tconfigurable?: boolean // Not modifiable once the property has been defined ?\n\twritable?: boolean\n}) {\n\treturn <T>(...properties: (keyof T)[]): GenericClassDecorator<T> =>\n\t\t(Base) => {\n\t\t\treturn class extends Base {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tfor (const key of properties) {\n\t\t\t\t\t\tObject.defineProperty(this, key, {\n\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptor(this, key),\n\t\t\t\t\t\t\t...descriptor,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n}\n\n/**\n * Decorator that marks methods, properties, or classes as deprecated\n * Provides warning messages when deprecated items are used\n */\nexport const deprecated = Object.assign(\n\tdecorator({\n\t\tmethod(original, _target, propertyKey) {\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.apply(this, args)\n\t\t\t}\n\t\t},\n\t\tgetter(original, _target, propertyKey) {\n\t\t\treturn function (this: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this)\n\t\t\t}\n\t\t},\n\t\tsetter(original, _target, propertyKey) {\n\t\t\treturn function (this: any, value: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this, value)\n\t\t\t}\n\t\t},\n\t\tclass(original) {\n\t\t\treturn class extends original {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tdeprecated.warn(this, 'constructor')\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tdefault(message: string) {\n\t\t\treturn decorator({\n\t\t\t\tmethod(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tgetter(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tsetter(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any, value: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this, value)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tclass(original) {\n\t\t\t\t\treturn class extends original {\n\t\t\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\t\t\tsuper(...args)\n\t\t\t\t\t\t\tdeprecated.warn(this, 'constructor', message)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t})\n\t\t},\n\t}),\n\t{\n\t\twarn: (target: any, propertyKey: PropertyKey, message?: string) => {\n\t\t\t// biome-ignore lint/suspicious/noConsole: To be overridden\n\t\t\tconsole.warn(\n\t\t\t\t`${target.constructor.name}.${String(propertyKey)} is deprecated${message ? `: ${message}` : ''}`\n\t\t\t)\n\t\t},\n\t}\n)\n\n/**\n * Creates a debounced method decorator that delays execution until after the delay period has passed\n * @param delay - The delay in milliseconds\n * @returns A method decorator that debounces method calls\n */\nexport function debounce(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _target, _propertyKey) {\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t// Clear existing timeout\n\t\t\t\tif (timeoutId) {\n\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t}\n\n\t\t\t\t// Set new timeout\n\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\toriginal.apply(this, args)\n\t\t\t\t\ttimeoutId = null\n\t\t\t\t}, delay)\n\t\t\t}\n\t\t},\n\t})\n}\n\n/**\n * Creates a throttled method decorator that limits execution to once per delay period\n * @param delay - The delay in milliseconds\n * @returns A method decorator that throttles method calls\n */\nexport function throttle(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _target, _propertyKey) {\n\t\t\tlet lastCallTime = 0\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tconst now = Date.now()\n\n\t\t\t\t// If enough time has passed since last call, execute immediately\n\t\t\t\tif (now - lastCallTime >= delay) {\n\t\t\t\t\t// Clear any pending timeout since we're executing now\n\t\t\t\t\tif (timeoutId) {\n\t\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}\n\t\t\t\t\tlastCallTime = now\n\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t}\n\n\t\t\t\t// Otherwise, schedule execution for when the delay period ends\n\t\t\t\tif (!timeoutId) {\n\t\t\t\t\tconst remainingTime = delay - (now - lastCallTime)\n\t\t\t\t\tconst scheduledArgs = [...args] // Capture args at scheduling time\n\t\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\t\tlastCallTime = Date.now()\n\t\t\t\t\t\toriginal.apply(this, scheduledArgs)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}, remainingTime)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t})\n}\n"],"names":[],"mappings":";;AAEA;AACA,MAAM,eAAe,GAA4C,EAAE;AACnE;;;AAGG;AACI,MAAM,MAAM,GAAG,SAAS,CAAC;AAC/B,IAAA,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAA;QACpC,OAAO,YAAA;YACN,MAAM,kBAAkB,GAAG,eAAe,CAAC,SAAS,CACnD,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAClD;YACD,IAAI,kBAAkB,GAAG,EAAE;AAC1B,gBAAA,MAAM,IAAI,KAAK,CACd,CAAA,8BAAA,EAAiC;qBAC/B,KAAK,CAAC,kBAAkB;qBACxB,GAAG,CAAC,CAAC,CAAC,KAAK,CAAA,EAAG,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA,CAAE;AAC3D,qBAAA,IAAI,CAAC,MAAM,CAAC,CAAA,SAAA,CAAW,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AAS,GAAG,IAAI;oBACjB,CAAC,EAAE,aAAa,CAAC;gBAClB;AACD,YAAA,CAAC;QACF,CAAC;AACD,KAAA,CAAC;AACH;;;;"}
|
package/dist/std-decorators.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var decorator = require('./chunks/decorator-
|
|
3
|
+
var decorator = require('./chunks/decorator-BQ2eBTCj.js');
|
|
4
4
|
|
|
5
5
|
// In order to avoid async re-entrance, we could use zone.js or something like that.
|
|
6
6
|
const syncCalculating = [];
|
|
@@ -9,7 +9,7 @@ const syncCalculating = [];
|
|
|
9
9
|
* Prevents circular dependencies and provides automatic cache invalidation
|
|
10
10
|
*/
|
|
11
11
|
const cached = decorator.decorator({
|
|
12
|
-
getter(original, propertyKey) {
|
|
12
|
+
getter(original, _target, propertyKey) {
|
|
13
13
|
return function () {
|
|
14
14
|
const alreadyCalculating = syncCalculating.findIndex((c) => c.object === this && c.prop === propertyKey);
|
|
15
15
|
if (alreadyCalculating > -1)
|
|
@@ -72,19 +72,19 @@ function describe(descriptor) {
|
|
|
72
72
|
* Provides warning messages when deprecated items are used
|
|
73
73
|
*/
|
|
74
74
|
const deprecated = Object.assign(decorator.decorator({
|
|
75
|
-
method(original, propertyKey) {
|
|
75
|
+
method(original, _target, propertyKey) {
|
|
76
76
|
return function (...args) {
|
|
77
77
|
deprecated.warn(this, propertyKey);
|
|
78
78
|
return original.apply(this, args);
|
|
79
79
|
};
|
|
80
80
|
},
|
|
81
|
-
getter(original, propertyKey) {
|
|
81
|
+
getter(original, _target, propertyKey) {
|
|
82
82
|
return function () {
|
|
83
83
|
deprecated.warn(this, propertyKey);
|
|
84
84
|
return original.call(this);
|
|
85
85
|
};
|
|
86
86
|
},
|
|
87
|
-
setter(original, propertyKey) {
|
|
87
|
+
setter(original, _target, propertyKey) {
|
|
88
88
|
return function (value) {
|
|
89
89
|
deprecated.warn(this, propertyKey);
|
|
90
90
|
return original.call(this, value);
|
|
@@ -100,19 +100,19 @@ const deprecated = Object.assign(decorator.decorator({
|
|
|
100
100
|
},
|
|
101
101
|
default(message) {
|
|
102
102
|
return decorator.decorator({
|
|
103
|
-
method(original, propertyKey) {
|
|
103
|
+
method(original, _target, propertyKey) {
|
|
104
104
|
return function (...args) {
|
|
105
105
|
deprecated.warn(this, propertyKey, message);
|
|
106
106
|
return original.apply(this, args);
|
|
107
107
|
};
|
|
108
108
|
},
|
|
109
|
-
getter(original, propertyKey) {
|
|
109
|
+
getter(original, _target, propertyKey) {
|
|
110
110
|
return function () {
|
|
111
111
|
deprecated.warn(this, propertyKey, message);
|
|
112
112
|
return original.call(this);
|
|
113
113
|
};
|
|
114
114
|
},
|
|
115
|
-
setter(original, propertyKey) {
|
|
115
|
+
setter(original, _target, propertyKey) {
|
|
116
116
|
return function (value) {
|
|
117
117
|
deprecated.warn(this, propertyKey, message);
|
|
118
118
|
return original.call(this, value);
|
|
@@ -141,7 +141,7 @@ const deprecated = Object.assign(decorator.decorator({
|
|
|
141
141
|
*/
|
|
142
142
|
function debounce(delay) {
|
|
143
143
|
return decorator.decorator({
|
|
144
|
-
method(original, _propertyKey) {
|
|
144
|
+
method(original, _target, _propertyKey) {
|
|
145
145
|
let timeoutId = null;
|
|
146
146
|
return function (...args) {
|
|
147
147
|
// Clear existing timeout
|
|
@@ -164,7 +164,7 @@ function debounce(delay) {
|
|
|
164
164
|
*/
|
|
165
165
|
function throttle(delay) {
|
|
166
166
|
return decorator.decorator({
|
|
167
|
-
method(original, _propertyKey) {
|
|
167
|
+
method(original, _target, _propertyKey) {
|
|
168
168
|
let lastCallTime = 0;
|
|
169
169
|
let timeoutId = null;
|
|
170
170
|
return function (...args) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"std-decorators.js","sources":["../src/std-decorators.ts"],"sourcesContent":["import { decorator, GenericClassDecorator } from './decorator'\n\n// In order to avoid async re-entrance, we could use zone.js or something like that.\nconst syncCalculating: { object: object; prop: PropertyKey }[] = []\n/**\n * Decorator that caches the result of a getter method and only recomputes when dependencies change\n * Prevents circular dependencies and provides automatic cache invalidation\n */\nexport const cached = decorator({\n\tgetter(original, propertyKey) {\n\t\treturn function (this: any) {\n\t\t\tconst alreadyCalculating = syncCalculating.findIndex(\n\t\t\t\t(c) => c.object === this && c.prop === propertyKey\n\t\t\t)\n\t\t\tif (alreadyCalculating > -1)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Circular dependency detected: ${syncCalculating\n\t\t\t\t\t\t.slice(alreadyCalculating)\n\t\t\t\t\t\t.map((c) => `${c.object.constructor.name}.${String(c.prop)}`)\n\t\t\t\t\t\t.join(' -> ')} -> again`\n\t\t\t\t)\n\t\t\tsyncCalculating.push({ object: this, prop: propertyKey })\n\t\t\ttry {\n\t\t\t\tconst rv = original.call(this)\n\t\t\t\tcache(this, propertyKey, rv)\n\t\t\t\treturn rv\n\t\t\t} finally {\n\t\t\t\tsyncCalculating.pop()\n\t\t\t}\n\t\t}\n\t},\n})\n\n/**\n * Checks if a property is cached (has a cached value)\n * @param object - The object to check\n * @param propertyKey - The property key to check\n * @returns True if the property has a cached value\n */\nexport function isCached(object: Object, propertyKey: PropertyKey) {\n\treturn !!Object.getOwnPropertyDescriptor(object, propertyKey)\n}\n\n/**\n * Caches a value for a property on an object\n * @param object - The object to cache the value on\n * @param propertyKey - The property key to cache\n * @param value - The value to cache\n */\nexport function cache(object: Object, propertyKey: PropertyKey, value: any) {\n\tObject.defineProperty(object, propertyKey, { value })\n}\n\n/**\n * Creates a decorator that modifies property descriptors for specified properties\n * @param descriptor - The descriptor properties to apply\n * @returns A class decorator that applies the descriptor to specified properties\n */\nexport function describe(descriptor: {\n\tenumerable?: boolean\n\tconfigurable?: boolean // Not modifiable once the property has been defined ?\n\twritable?: boolean\n}) {\n\treturn <T>(...properties: (keyof T)[]): GenericClassDecorator<T> =>\n\t\t(Base) => {\n\t\t\treturn class extends Base {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tfor (const key of properties) {\n\t\t\t\t\t\tObject.defineProperty(this, key, {\n\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptor(this, key),\n\t\t\t\t\t\t\t...descriptor,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n}\n\n/**\n * Decorator that marks methods, properties, or classes as deprecated\n * Provides warning messages when deprecated items are used\n */\nexport const deprecated = Object.assign(\n\tdecorator({\n\t\tmethod(original, propertyKey) {\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.apply(this, args)\n\t\t\t}\n\t\t},\n\t\tgetter(original, propertyKey) {\n\t\t\treturn function (this: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this)\n\t\t\t}\n\t\t},\n\t\tsetter(original, propertyKey) {\n\t\t\treturn function (this: any, value: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this, value)\n\t\t\t}\n\t\t},\n\t\tclass(original) {\n\t\t\treturn class extends original {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tdeprecated.warn(this, 'constructor')\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tdefault(message: string) {\n\t\t\treturn decorator({\n\t\t\t\tmethod(original, propertyKey) {\n\t\t\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tgetter(original, propertyKey) {\n\t\t\t\t\treturn function (this: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tsetter(original, propertyKey) {\n\t\t\t\t\treturn function (this: any, value: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this, value)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tclass(original) {\n\t\t\t\t\treturn class extends original {\n\t\t\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\t\t\tsuper(...args)\n\t\t\t\t\t\t\tdeprecated.warn(this, 'constructor', message)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t})\n\t\t},\n\t}),\n\t{\n\t\twarn: (target: any, propertyKey: PropertyKey, message?: string) => {\n\t\t\t// biome-ignore lint/suspicious/noConsole: To be overridden\n\t\t\tconsole.warn(\n\t\t\t\t`${target.constructor.name}.${String(propertyKey)} is deprecated${message ? `: ${message}` : ''}`\n\t\t\t)\n\t\t},\n\t}\n)\n\n/**\n * Creates a debounced method decorator that delays execution until after the delay period has passed\n * @param delay - The delay in milliseconds\n * @returns A method decorator that debounces method calls\n */\nexport function debounce(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _propertyKey) {\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t// Clear existing timeout\n\t\t\t\tif (timeoutId) {\n\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t}\n\n\t\t\t\t// Set new timeout\n\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\toriginal.apply(this, args)\n\t\t\t\t\ttimeoutId = null\n\t\t\t\t}, delay)\n\t\t\t}\n\t\t},\n\t})\n}\n\n/**\n * Creates a throttled method decorator that limits execution to once per delay period\n * @param delay - The delay in milliseconds\n * @returns A method decorator that throttles method calls\n */\nexport function throttle(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _propertyKey) {\n\t\t\tlet lastCallTime = 0\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tconst now = Date.now()\n\n\t\t\t\t// If enough time has passed since last call, execute immediately\n\t\t\t\tif (now - lastCallTime >= delay) {\n\t\t\t\t\t// Clear any pending timeout since we're executing now\n\t\t\t\t\tif (timeoutId) {\n\t\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}\n\t\t\t\t\tlastCallTime = now\n\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t}\n\n\t\t\t\t// Otherwise, schedule execution for when the delay period ends\n\t\t\t\tif (!timeoutId) {\n\t\t\t\t\tconst remainingTime = delay - (now - lastCallTime)\n\t\t\t\t\tconst scheduledArgs = [...args] // Capture args at scheduling time\n\t\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\t\tlastCallTime = Date.now()\n\t\t\t\t\t\toriginal.apply(this, scheduledArgs)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}, remainingTime)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t})\n}\n"],"names":["decorator"],"mappings":";;;;AAEA;AACA,MAAM,eAAe,GAA4C,EAAE;AACnE;;;AAGG;AACI,MAAM,MAAM,GAAGA,mBAAS,CAAC;IAC/B,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAA;QAC3B,OAAO,YAAA;YACN,MAAM,kBAAkB,GAAG,eAAe,CAAC,SAAS,CACnD,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAClD;YACD,IAAI,kBAAkB,GAAG,EAAE;AAC1B,gBAAA,MAAM,IAAI,KAAK,CACd,CAAA,8BAAA,EAAiC;qBAC/B,KAAK,CAAC,kBAAkB;qBACxB,GAAG,CAAC,CAAC,CAAC,KAAK,CAAA,EAAG,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA,CAAE;AAC3D,qBAAA,IAAI,CAAC,MAAM,CAAC,CAAA,SAAA,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|
|
1
|
+
{"version":3,"file":"std-decorators.js","sources":["../src/std-decorators.ts"],"sourcesContent":["import { decorator, type GenericClassDecorator } from './decorator'\n\n// In order to avoid async re-entrance, we could use zone.js or something like that.\nconst syncCalculating: { object: object; prop: PropertyKey }[] = []\n/**\n * Decorator that caches the result of a getter method and only recomputes when dependencies change\n * Prevents circular dependencies and provides automatic cache invalidation\n */\nexport const cached = decorator({\n\tgetter(original, _target, propertyKey) {\n\t\treturn function (this: any) {\n\t\t\tconst alreadyCalculating = syncCalculating.findIndex(\n\t\t\t\t(c) => c.object === this && c.prop === propertyKey\n\t\t\t)\n\t\t\tif (alreadyCalculating > -1)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Circular dependency detected: ${syncCalculating\n\t\t\t\t\t\t.slice(alreadyCalculating)\n\t\t\t\t\t\t.map((c) => `${c.object.constructor.name}.${String(c.prop)}`)\n\t\t\t\t\t\t.join(' -> ')} -> again`\n\t\t\t\t)\n\t\t\tsyncCalculating.push({ object: this, prop: propertyKey })\n\t\t\ttry {\n\t\t\t\tconst rv = original.call(this)\n\t\t\t\tcache(this, propertyKey, rv)\n\t\t\t\treturn rv\n\t\t\t} finally {\n\t\t\t\tsyncCalculating.pop()\n\t\t\t}\n\t\t}\n\t},\n})\n\n/**\n * Checks if a property is cached (has a cached value)\n * @param object - The object to check\n * @param propertyKey - The property key to check\n * @returns True if the property has a cached value\n */\nexport function isCached(object: Object, propertyKey: PropertyKey) {\n\treturn !!Object.getOwnPropertyDescriptor(object, propertyKey)\n}\n\n/**\n * Caches a value for a property on an object\n * @param object - The object to cache the value on\n * @param propertyKey - The property key to cache\n * @param value - The value to cache\n */\nexport function cache(object: Object, propertyKey: PropertyKey, value: any) {\n\tObject.defineProperty(object, propertyKey, { value })\n}\n\n/**\n * Creates a decorator that modifies property descriptors for specified properties\n * @param descriptor - The descriptor properties to apply\n * @returns A class decorator that applies the descriptor to specified properties\n */\nexport function describe(descriptor: {\n\tenumerable?: boolean\n\tconfigurable?: boolean // Not modifiable once the property has been defined ?\n\twritable?: boolean\n}) {\n\treturn <T>(...properties: (keyof T)[]): GenericClassDecorator<T> =>\n\t\t(Base) => {\n\t\t\treturn class extends Base {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tfor (const key of properties) {\n\t\t\t\t\t\tObject.defineProperty(this, key, {\n\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptor(this, key),\n\t\t\t\t\t\t\t...descriptor,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n}\n\n/**\n * Decorator that marks methods, properties, or classes as deprecated\n * Provides warning messages when deprecated items are used\n */\nexport const deprecated = Object.assign(\n\tdecorator({\n\t\tmethod(original, _target, propertyKey) {\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.apply(this, args)\n\t\t\t}\n\t\t},\n\t\tgetter(original, _target, propertyKey) {\n\t\t\treturn function (this: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this)\n\t\t\t}\n\t\t},\n\t\tsetter(original, _target, propertyKey) {\n\t\t\treturn function (this: any, value: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this, value)\n\t\t\t}\n\t\t},\n\t\tclass(original) {\n\t\t\treturn class extends original {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tdeprecated.warn(this, 'constructor')\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tdefault(message: string) {\n\t\t\treturn decorator({\n\t\t\t\tmethod(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tgetter(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tsetter(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any, value: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this, value)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tclass(original) {\n\t\t\t\t\treturn class extends original {\n\t\t\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\t\t\tsuper(...args)\n\t\t\t\t\t\t\tdeprecated.warn(this, 'constructor', message)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t})\n\t\t},\n\t}),\n\t{\n\t\twarn: (target: any, propertyKey: PropertyKey, message?: string) => {\n\t\t\t// biome-ignore lint/suspicious/noConsole: To be overridden\n\t\t\tconsole.warn(\n\t\t\t\t`${target.constructor.name}.${String(propertyKey)} is deprecated${message ? `: ${message}` : ''}`\n\t\t\t)\n\t\t},\n\t}\n)\n\n/**\n * Creates a debounced method decorator that delays execution until after the delay period has passed\n * @param delay - The delay in milliseconds\n * @returns A method decorator that debounces method calls\n */\nexport function debounce(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _target, _propertyKey) {\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t// Clear existing timeout\n\t\t\t\tif (timeoutId) {\n\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t}\n\n\t\t\t\t// Set new timeout\n\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\toriginal.apply(this, args)\n\t\t\t\t\ttimeoutId = null\n\t\t\t\t}, delay)\n\t\t\t}\n\t\t},\n\t})\n}\n\n/**\n * Creates a throttled method decorator that limits execution to once per delay period\n * @param delay - The delay in milliseconds\n * @returns A method decorator that throttles method calls\n */\nexport function throttle(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _target, _propertyKey) {\n\t\t\tlet lastCallTime = 0\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tconst now = Date.now()\n\n\t\t\t\t// If enough time has passed since last call, execute immediately\n\t\t\t\tif (now - lastCallTime >= delay) {\n\t\t\t\t\t// Clear any pending timeout since we're executing now\n\t\t\t\t\tif (timeoutId) {\n\t\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}\n\t\t\t\t\tlastCallTime = now\n\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t}\n\n\t\t\t\t// Otherwise, schedule execution for when the delay period ends\n\t\t\t\tif (!timeoutId) {\n\t\t\t\t\tconst remainingTime = delay - (now - lastCallTime)\n\t\t\t\t\tconst scheduledArgs = [...args] // Capture args at scheduling time\n\t\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\t\tlastCallTime = Date.now()\n\t\t\t\t\t\toriginal.apply(this, scheduledArgs)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}, remainingTime)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t})\n}\n"],"names":["decorator"],"mappings":";;;;AAEA;AACA,MAAM,eAAe,GAA4C,EAAE;AACnE;;;AAGG;AACI,MAAM,MAAM,GAAGA,mBAAS,CAAC;AAC/B,IAAA,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAA;QACpC,OAAO,YAAA;YACN,MAAM,kBAAkB,GAAG,eAAe,CAAC,SAAS,CACnD,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAClD;YACD,IAAI,kBAAkB,GAAG,EAAE;AAC1B,gBAAA,MAAM,IAAI,KAAK,CACd,CAAA,8BAAA,EAAiC;qBAC/B,KAAK,CAAC,k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AClD,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;AAC/B,oBAAA,SAAS,GAAG,UAAU,CAAC,MAAK;AAC3B,wBAAA,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE;AACzB,wBAAA,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC;wBACnC,SAAS,GAAG,IAAI;oBACjB,CAAC,EAAE,aAAa,CAAC;gBAClB;AACD,YAAA,CAAC;QACF,CAAC;AACD,KAAA,CAAC;AACH;;;;;;;;;;"}
|
package/docs/ai/manual.md
CHANGED
|
@@ -2,104 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
> [!IMPORTANT]
|
|
4
4
|
> **Identity**: You are an AI Agent. This document is written for **YOU**.
|
|
5
|
-
> **Purpose**: This file defines the protocols
|
|
6
|
-
>
|
|
7
|
-
> For exact TypeScript signatures of the entire library, consult the **[API Reference for Agents](./api-reference.md)**.
|
|
5
|
+
> **Purpose**: This file defines the protocols and high-level strategy for working with the `mutts` reactivity system.
|
|
8
6
|
|
|
9
|
-
## 1.
|
|
10
|
-
|
|
7
|
+
## 1. Technical Documentation
|
|
8
|
+
Do not rely on outdated internal knowledge. Use the current documentation as your primary source of truth:
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import { enableIntrospection, options } from 'mutts/introspection'
|
|
10
|
+
- **[Debugging Tools](../reactive/debugging.md)**: How to use introspection, troubleshoot cycles, and detect memoization discrepancies.
|
|
11
|
+
- **[API Reference](./api-reference.md)**: Exact TypeScript signatures for library functions.
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```
|
|
13
|
+
## 2. Debugging Protocol
|
|
14
|
+
When you encounter reactivity bugs (infinite loops, unexpected updates), **DO NOT GUESS**.
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import { getDependencyGraph } from 'mutts/introspection'
|
|
16
|
+
1. **Introspect**: Use `mutts/introspection` to inspect the dependency graph or mutation history.
|
|
17
|
+
2. **Analyze Errors**: `ReactiveError` objects contain `debugInfo` with causal chains and creation stacks. Use them to trace the fault.
|
|
18
|
+
3. **Verify**: Use `reactiveOptions.onMemoizationDiscrepancy` in tests to ensure your changes didn't break dependency tracking.
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
**
|
|
20
|
+
## 3. Architecture Constraints
|
|
21
|
+
1. **No Internal Access**: Do not access properties starting with `_mutts_` directly.
|
|
22
|
+
2. **Explicit Naming**: Always name your effects (`effect(fn, { name: '...' })`) to make future debugging easier for yourself or other agents.
|
|
23
|
+
3. **Affirmative State**: Prefer derived state and effects over imperative event-driven updates.
|
|
30
24
|
|
|
31
|
-
### Mutation History
|
|
32
|
-
Understanding "What just happened".
|
|
33
|
-
```typescript
|
|
34
|
-
import { getMutationHistory } from 'mutts/introspection'
|
|
35
|
-
|
|
36
|
-
const history = getMutationHistory()
|
|
37
|
-
/*
|
|
38
|
-
Returns Array<{
|
|
39
|
-
id: number,
|
|
40
|
-
type: 'set' | 'add' | 'delete',
|
|
41
|
-
prop: string | symbol,
|
|
42
|
-
oldValue: any,
|
|
43
|
-
newValue: any,
|
|
44
|
-
objectName: string, // "Human readable name"
|
|
45
|
-
source: string, // "Effect X" or "External"
|
|
46
|
-
timestamp: number
|
|
47
|
-
}>
|
|
48
|
-
*/
|
|
49
|
-
```
|
|
50
|
-
**Agent Protocol**: When diagnosing "why is this value wrong?", check the *last mutation* of that property in history.
|
|
51
|
-
|
|
52
|
-
## 2. Structured Error Handling
|
|
53
|
-
`mutts` throws `ReactiveError` instances. These are designed to be machine-parseable.
|
|
54
|
-
|
|
55
|
-
### ReactiveErrorCode
|
|
56
|
-
Always check `error.debugInfo.code`.
|
|
57
|
-
```typescript
|
|
58
|
-
enum ReactiveErrorCode {
|
|
59
|
-
CycleDetected = 'CYCLE_DETECTED',
|
|
60
|
-
MaxDepthExceeded = 'MAX_DEPTH_EXCEEDED',
|
|
61
|
-
MaxReactionExceeded = 'MAX_REACTION_EXCEEDED',
|
|
62
|
-
WriteInComputed = 'WRITE_IN_COMPUTED',
|
|
63
|
-
TrackingError = 'TRACKING_ERROR'
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Debugging Protocols
|
|
68
|
-
|
|
69
|
-
#### Protocol: Handling `CycleDetected` / `MaxDepthExceeded`
|
|
70
|
-
**Symptom**: `ReactiveError` with code `CycleDetected` or `MaxDepthExceeded`.
|
|
71
|
-
**Action**:
|
|
72
|
-
1. Read `error.debugInfo.cycle` (Array of effect names).
|
|
73
|
-
2. **CRITICAL**: Read `error.debugInfo.causalChain`.
|
|
74
|
-
* It tells you the *logical path*: `Effect A` -> (modifies `x`) -> `Effect B` -> (modifies `y`) -> `Effect A`.
|
|
75
|
-
3. **CRITICAL**: Read `error.debugInfo.creationStack`.
|
|
76
|
-
* This gives you the **File path and Line number** where the problematic effect was defined.
|
|
77
|
-
|
|
78
|
-
**Example Error Object**:
|
|
79
|
-
```json
|
|
80
|
-
{
|
|
81
|
-
"message": "[reactive] Max effect chain reached...",
|
|
82
|
-
"debugInfo": {
|
|
83
|
-
"code": "MAX_DEPTH_EXCEEDED",
|
|
84
|
-
"causalChain": [
|
|
85
|
-
"Effect(Anonymous) -> (set 'count') -> Effect(Display)",
|
|
86
|
-
"Effect(Display) -> (set 'dummy') -> Effect(Anonymous)"
|
|
87
|
-
],
|
|
88
|
-
"creationStack": " at tests/my-test.ts:45:10\n at ...",
|
|
89
|
-
"cycle": ["Effect(Anonymous)", "Effect(Display)"]
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## 3. Strict Mode
|
|
95
|
-
If you are writing new code that might be complex, verify it with "Strict Mode".
|
|
96
|
-
This forces a graph check *before* execution, preventing infinite loops from hanging the runtime.
|
|
97
|
-
```typescript
|
|
98
|
-
import { options } from 'mutts/introspection'
|
|
99
|
-
options.cycleHandling = 'strict'
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## 4. Architecture Constraints for Agents
|
|
103
|
-
1. **Do not** access properties starting with `_mutts_` directly unless instructed. These are internal implementation details.
|
|
104
|
-
2. **Do not** rely on `batchQueue` global state in your reasoning; it is ephemeral.
|
|
105
|
-
3. **Do** name your effects when possible (`effect(() => {}, { name: 'MyEffect' })`) to make your own future debugging easier.
|