@alloy-js/core 0.23.0-dev.18 → 0.23.0-dev.19
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/dist/dev/src/devtools/devtools-server.browser.js +3 -0
- package/dist/dev/src/devtools/devtools-server.browser.js.map +1 -1
- package/dist/dev/src/devtools/devtools-server.js +15 -1
- package/dist/dev/src/devtools/devtools-server.js.map +1 -1
- package/dist/dev/src/reactivity.js +44 -34
- package/dist/dev/src/reactivity.js.map +1 -1
- package/dist/dev/test/reactivity/shallow-reactive.test.js +4 -0
- package/dist/dev/test/reactivity/shallow-reactive.test.js.map +1 -1
- package/dist/src/devtools/devtools-server.browser.d.ts +1 -0
- package/dist/src/devtools/devtools-server.browser.d.ts.map +1 -1
- package/dist/src/devtools/devtools-server.browser.js +3 -0
- package/dist/src/devtools/devtools-server.browser.js.map +1 -1
- package/dist/src/devtools/devtools-server.d.ts +5 -0
- package/dist/src/devtools/devtools-server.d.ts.map +1 -1
- package/dist/src/devtools/devtools-server.js +15 -1
- package/dist/src/devtools/devtools-server.js.map +1 -1
- package/dist/src/reactivity.d.ts.map +1 -1
- package/dist/src/reactivity.js +44 -34
- package/dist/src/reactivity.js.map +1 -1
- package/dist/test/reactivity/shallow-reactive.test.js +4 -0
- package/dist/test/reactivity/shallow-reactive.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/devtools/devtools-server.browser.ts +4 -0
- package/src/devtools/devtools-server.ts +16 -1
- package/src/reactivity.ts +53 -40
- package/test/reactivity/shallow-reactive.test.tsx +4 -0
package/package.json
CHANGED
|
@@ -153,6 +153,19 @@ function isNodeEnvironment() {
|
|
|
153
153
|
);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
// Cached once at module load. Stable for production runs. Tests that modify
|
|
157
|
+
// process.env.ALLOY_DEBUG dynamically must call refreshDebugState() afterward.
|
|
158
|
+
let _envDebugEnabled: boolean =
|
|
159
|
+
isNodeEnvironment() && Boolean(process.env.ALLOY_DEBUG);
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Invalidates the cached env-var result for isDevtoolsEnabled(). Call this in
|
|
163
|
+
* test beforeEach hooks after modifying process.env.ALLOY_DEBUG.
|
|
164
|
+
*/
|
|
165
|
+
export function refreshDebugState(): void {
|
|
166
|
+
_envDebugEnabled = isNodeEnvironment() && Boolean(process.env.ALLOY_DEBUG);
|
|
167
|
+
}
|
|
168
|
+
|
|
156
169
|
function getCwd() {
|
|
157
170
|
if (!isNodeEnvironment()) return undefined;
|
|
158
171
|
try {
|
|
@@ -177,7 +190,7 @@ function resolveDebugPort() {
|
|
|
177
190
|
/** Returns true when devtools are enabled (via env var or explicit call). */
|
|
178
191
|
export function isDevtoolsEnabled() {
|
|
179
192
|
if (!isNodeEnvironment()) return false;
|
|
180
|
-
return devtoolsExplicitlyEnabled ||
|
|
193
|
+
return devtoolsExplicitlyEnabled || _envDebugEnabled;
|
|
181
194
|
}
|
|
182
195
|
|
|
183
196
|
/** Returns true when a devtools client is currently connected. */
|
|
@@ -463,6 +476,8 @@ export async function resetDevtoolsServerForTests() {
|
|
|
463
476
|
loggedDevtoolsLinks = false;
|
|
464
477
|
subscribedPromise = null;
|
|
465
478
|
resolveSubscribed = null;
|
|
479
|
+
// Re-read the env var in case tests modified process.env.ALLOY_DEBUG
|
|
480
|
+
refreshDebugState();
|
|
466
481
|
// Close the trace DB so each test starts fresh
|
|
467
482
|
closeTrace();
|
|
468
483
|
}
|
package/src/reactivity.ts
CHANGED
|
@@ -255,13 +255,16 @@ export function effect<T>(
|
|
|
255
255
|
};
|
|
256
256
|
|
|
257
257
|
const debugInfo = options?.debug;
|
|
258
|
-
const effectId =
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
258
|
+
const effectId =
|
|
259
|
+
isDebugEnabled() ?
|
|
260
|
+
debug.effect.register({
|
|
261
|
+
name: debugInfo?.name ?? fn.name,
|
|
262
|
+
type: debugInfo?.type,
|
|
263
|
+
createdAt: captureSourceLocation(),
|
|
264
|
+
contextId: context.id,
|
|
265
|
+
ownerContextId: resolveOwnerEffectContextId(context),
|
|
266
|
+
})
|
|
267
|
+
: -1;
|
|
265
268
|
|
|
266
269
|
if (effectId !== -1) {
|
|
267
270
|
context.meta ??= {};
|
|
@@ -458,13 +461,15 @@ export function ref<T>(
|
|
|
458
461
|
options?: { isInfrastructure?: boolean },
|
|
459
462
|
): Ref<T> {
|
|
460
463
|
const result = vueRef(value) as Ref<T>;
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
464
|
+
if (isDebugEnabled()) {
|
|
465
|
+
debug.effect.registerRef({
|
|
466
|
+
id: refId(result),
|
|
467
|
+
kind: "ref",
|
|
468
|
+
createdAt: captureSourceLocation(),
|
|
469
|
+
createdByEffectId: globalContext?.meta?.effectId,
|
|
470
|
+
isInfrastructure: options?.isInfrastructure,
|
|
471
|
+
});
|
|
472
|
+
}
|
|
468
473
|
return result;
|
|
469
474
|
}
|
|
470
475
|
|
|
@@ -492,24 +497,28 @@ export function shallowReactive<T extends object>(
|
|
|
492
497
|
|
|
493
498
|
export function shallowRef<T>(value?: T, options?: { label?: string }): Ref<T> {
|
|
494
499
|
const result = vueShallowRef(value) as Ref<T>;
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
500
|
+
if (isDebugEnabled()) {
|
|
501
|
+
debug.effect.registerRef({
|
|
502
|
+
id: refId(result),
|
|
503
|
+
kind: "shallowRef",
|
|
504
|
+
label: options?.label,
|
|
505
|
+
createdAt: captureSourceLocation(),
|
|
506
|
+
createdByEffectId: globalContext?.meta?.effectId,
|
|
507
|
+
});
|
|
508
|
+
}
|
|
502
509
|
return result;
|
|
503
510
|
}
|
|
504
511
|
|
|
505
512
|
export function computed<T>(getter: () => T): Ref<T> {
|
|
506
513
|
const result = vueComputed(getter) as Ref<T>;
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
514
|
+
if (isDebugEnabled()) {
|
|
515
|
+
debug.effect.registerRef({
|
|
516
|
+
id: refId(result),
|
|
517
|
+
kind: "computed",
|
|
518
|
+
createdAt: captureSourceLocation(),
|
|
519
|
+
createdByEffectId: globalContext?.meta?.effectId,
|
|
520
|
+
});
|
|
521
|
+
}
|
|
513
522
|
return result;
|
|
514
523
|
}
|
|
515
524
|
|
|
@@ -522,12 +531,14 @@ export function toRef<T extends object, K extends keyof T>(
|
|
|
522
531
|
defaultValue === undefined ?
|
|
523
532
|
(vueToRef(object, key) as Ref<T[K]>)
|
|
524
533
|
: (vueToRef(object, key, defaultValue) as Ref<T[K]>);
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
534
|
+
if (isDebugEnabled()) {
|
|
535
|
+
debug.effect.registerRef({
|
|
536
|
+
id: refId(result),
|
|
537
|
+
kind: "toRef",
|
|
538
|
+
createdAt: captureSourceLocation(),
|
|
539
|
+
createdByEffectId: globalContext?.meta?.effectId,
|
|
540
|
+
});
|
|
541
|
+
}
|
|
531
542
|
return result;
|
|
532
543
|
}
|
|
533
544
|
|
|
@@ -535,13 +546,15 @@ export function toRefs<T extends object>(
|
|
|
535
546
|
object: T,
|
|
536
547
|
): { [K in keyof T]: Ref<T[K]> } {
|
|
537
548
|
const result = vueToRefs(object) as { [K in keyof T]: Ref<T[K]> };
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
549
|
+
if (isDebugEnabled()) {
|
|
550
|
+
for (const refValue of Object.values(result) as Ref<unknown>[]) {
|
|
551
|
+
debug.effect.registerRef({
|
|
552
|
+
id: refId(refValue),
|
|
553
|
+
kind: "toRef",
|
|
554
|
+
createdAt: captureSourceLocation(),
|
|
555
|
+
createdByEffectId: globalContext?.meta?.effectId,
|
|
556
|
+
});
|
|
557
|
+
}
|
|
545
558
|
}
|
|
546
559
|
return result;
|
|
547
560
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { refreshDebugState } from "../../src/devtools/devtools-server.js";
|
|
2
3
|
import {
|
|
3
4
|
getReactiveCreationLocation,
|
|
4
5
|
shallowReactive,
|
|
@@ -10,6 +11,7 @@ describe("shallowReactive creation location", () => {
|
|
|
10
11
|
beforeEach(() => {
|
|
11
12
|
origDebug = process.env.ALLOY_DEBUG;
|
|
12
13
|
process.env.ALLOY_DEBUG = "1";
|
|
14
|
+
refreshDebugState();
|
|
13
15
|
});
|
|
14
16
|
|
|
15
17
|
afterEach(() => {
|
|
@@ -18,6 +20,7 @@ describe("shallowReactive creation location", () => {
|
|
|
18
20
|
} else {
|
|
19
21
|
process.env.ALLOY_DEBUG = origDebug;
|
|
20
22
|
}
|
|
23
|
+
refreshDebugState();
|
|
21
24
|
});
|
|
22
25
|
|
|
23
26
|
it("stores creation location keyed by raw target when debug enabled", () => {
|
|
@@ -31,6 +34,7 @@ describe("shallowReactive creation location", () => {
|
|
|
31
34
|
|
|
32
35
|
it("does not store location when debug is disabled", () => {
|
|
33
36
|
delete process.env.ALLOY_DEBUG;
|
|
37
|
+
refreshDebugState();
|
|
34
38
|
const raw = { y: 2 };
|
|
35
39
|
shallowReactive(raw);
|
|
36
40
|
|