@praxisjs/devtools 0.2.5 → 0.2.7
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/CHANGELOG.md +28 -0
- package/assets/uno.generated.css +2 -1
- package/dist/index.d.ts +4 -25
- package/dist/index.js +969 -627
- package/package.json +6 -6
- package/src/__tests__/debug.test.ts +82 -12
- package/src/__tests__/event-bus.test.ts +47 -0
- package/src/__tests__/registry.test.ts +55 -0
- package/src/__tests__/trace.test.ts +51 -0
- package/src/core/event-bus.ts +17 -3
- package/src/decorators/debug.ts +91 -147
- package/src/decorators/trace.ts +39 -36
package/src/decorators/trace.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
import type { RootComponent } from "@praxisjs/core/internal";
|
|
2
|
+
import {
|
|
3
|
+
createClassDecorator,
|
|
4
|
+
ClassBehavior,
|
|
5
|
+
type ClassEnhancement,
|
|
6
|
+
} from "@praxisjs/decorators";
|
|
7
|
+
|
|
1
8
|
import { Registry } from "../core/registry";
|
|
2
9
|
|
|
3
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
11
|
type AnyConstructor = new (...args: any[]) => any;
|
|
5
12
|
|
|
13
|
+
const EXTRA_HOOKS = ["onBeforeUpdate", "onUpdate", "onAfterUpdate"] as const;
|
|
14
|
+
|
|
6
15
|
/**
|
|
7
16
|
* Instruments a component class to report renders and lifecycle events
|
|
8
17
|
* to the devtools panel.
|
|
@@ -11,58 +20,52 @@ type AnyConstructor = new (...args: any[]) => any;
|
|
|
11
20
|
* @Component()
|
|
12
21
|
* class MyComponent extends StatefulComponent { ... }
|
|
13
22
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const name = constructor.name;
|
|
23
|
+
class TraceBehavior extends ClassBehavior {
|
|
24
|
+
create(instance: RootComponent): ClassEnhancement {
|
|
17
25
|
const registry = Registry.instance;
|
|
18
|
-
const proto = constructor.prototype as Record<string, unknown>;
|
|
19
|
-
|
|
20
|
-
// ── render() ──────────────────────────────────────────────────────────
|
|
21
|
-
const originalRender = proto.render as
|
|
22
|
-
| ((...args: unknown[]) => unknown)
|
|
23
|
-
| undefined;
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
return {
|
|
28
|
+
onMount() {
|
|
29
|
+
registry.recordLifecycle(instance, "onMount");
|
|
30
|
+
},
|
|
31
|
+
onUnmount() {
|
|
32
|
+
registry.recordLifecycle(instance, "onUnmount");
|
|
33
|
+
},
|
|
34
|
+
render(originalRender) {
|
|
27
35
|
const start = performance.now();
|
|
28
|
-
const result = originalRender
|
|
36
|
+
const result = originalRender();
|
|
29
37
|
const duration = performance.now() - start;
|
|
30
|
-
registry.recordRender(
|
|
38
|
+
registry.recordRender(instance, duration);
|
|
31
39
|
return result;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
initialize(Enhanced: AnyConstructor, original: AnyConstructor): void {
|
|
45
|
+
const name = original.name;
|
|
46
|
+
const registry = Registry.instance;
|
|
47
|
+
const proto = Enhanced.prototype as Record<string, unknown>;
|
|
39
48
|
|
|
49
|
+
// onBeforeMount — also registers the component instance
|
|
50
|
+
const originalOnBeforeMount = proto.onBeforeMount as ((...args: unknown[]) => unknown) | undefined;
|
|
40
51
|
proto.onBeforeMount = function (this: object, ...args: unknown[]) {
|
|
41
52
|
registry.registerComponent(this, name);
|
|
42
53
|
registry.recordLifecycle(this, "onBeforeMount");
|
|
43
54
|
return originalOnBeforeMount?.call(this, ...args);
|
|
44
55
|
};
|
|
45
56
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"onMount",
|
|
49
|
-
"onUnmount",
|
|
50
|
-
"onBeforeUpdate",
|
|
51
|
-
"onUpdate",
|
|
52
|
-
"onAfterUpdate",
|
|
53
|
-
] as const;
|
|
54
|
-
|
|
55
|
-
for (const hook of hooks) {
|
|
56
|
-
const original = proto[hook] as
|
|
57
|
-
| ((...args: unknown[]) => unknown)
|
|
58
|
-
| undefined;
|
|
59
|
-
|
|
57
|
+
for (const hook of EXTRA_HOOKS) {
|
|
58
|
+
const orig = proto[hook] as ((...args: unknown[]) => unknown) | undefined;
|
|
60
59
|
proto[hook] = function (this: object, ...args: unknown[]) {
|
|
61
60
|
registry.recordLifecycle(this, hook);
|
|
62
|
-
return
|
|
61
|
+
return orig?.call(this, ...args);
|
|
63
62
|
};
|
|
64
63
|
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const traceBehavior = new TraceBehavior();
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
export function Trace() {
|
|
70
|
+
return createClassDecorator(traceBehavior);
|
|
68
71
|
}
|