8000 feat(devtools): update getSignalGraph by milomg · Pull Request #61541 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

feat(devtools): update getSignalGraph #61541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(devtools): update get signal graph
add a function that we can inspect to jump to the source of a signal, and give every signal a unique id
that devtools can use to match signals across calls to getSignalGraph
  • Loading branch information
milomg committed May 22, 2025
commit c041a2d30e048e3d3492342e0a04d703fe85c6f0
33 changes: 28 additions & 5 deletions packages/core/src/render3/util/signal_debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ import {

export interface DebugSignalGraphNode {
kind: string;
id: string;
epoch: number;
label?: string;
value?: unknown;
debuggableFn?: () => unknown;
}

export interface DebugSignalGraphEdge {
Expand Down Expand Up @@ -84,6 +87,9 @@ function getTemplateConsumer(injector: NodeInjector): ReactiveLViewConsumer | nu
return templateLView[REACTIVE_TEMPLATE_CONSUMER];
}

const signalDebugMap = new WeakMap<ReactiveNode, string>();
let counter = 0;

function getNodesAndEdgesFromSignalMap(signalMap: ReadonlyMap<ReactiveNode, ReactiveNode[]>): {
nodes: DebugSignalGraphNode[];
edges: DebugSignalGraphEdge[];
Expand All @@ -95,27 +101,44 @@ function getNodesAndEdgesFromSignalMap(signalMap: ReadonlyMap<ReactiveNode, Reac
for (const [consumer, producers] of signalMap.entries()) {
const consumerIndex = nodes.indexOf(consumer);

let id = signalDebugMap.get(consumer);
if (!id) {
counter++;
id = counter.toString();
signalDebugMap.set(consumer, id);
}

// collect node
if (isComputedNode(consumer) || isSignalNode(consumer)) {
if (isComputedNode(consumer)) {
debugSignalGraphNodes.push({
label: consumer.debugName,
value: consumer.value,
kind: consumer.kind,
epoch: consumer.version,
debuggableFn: consumer.computation,
id,
});
} else if (isTemplateEffectNode(consumer)) {
} else if (isSignalNode(consumer)) {
debugSignalGraphNodes.push({
label: consumer.debugName ?? consumer.lView?.[HOST]?.tagName?.toLowerCase?.(),
label: consumer.debugName,
value: consumer.value,
kind: consumer.kind,
epoch: consumer.version,
id,
});
} else if (isEffectNode(consumer)) {
} else if (isTemplateEffectNode(consumer)) {
debugSignalGraphNodes.push({
label: consumer.debugName,
label: consumer.debugName ?? consumer.lView?.[HOST]?.tagName?.toLowerCase?.(),
kind: consumer.kind,
epoch: consumer.version,
id,
});
} else {
debugSignalGraphNodes.push({
label: consumer.debugName,
kind: consumer.kind,
epoch: consumer.version,
id,
});
}

Expand Down
0