Skip to content

Commit 5aac56f

Browse files
authored
feat(extension): fold repeated children (#810)
Closes #760. Applies the same folding as root nodes to children. Basically keeps track of a `firstChildren` just the same way we hold `firstUpdate`.
1 parent 6851213 commit 5aac56f

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

.changeset/hot-mugs-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"preact-signals-devtools": minor
3+
---
4+
5+
Automatically fold child updates and show first/last value.

extension/src/components/UpdateTreeNode.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ export function UpdateTreeNodeComponent({ node }: UpdateTreeNodeProps) {
1717
const nodeCount = node.type === "group" ? node.count : undefined;
1818
const firstUpdate = node.type === "group" ? node.firstUpdate : undefined;
1919

20+
let childrenToRender: UpdateTreeNode[];
21+
22+
if (node.type === "group" && node.firstChildren) {
23+
childrenToRender = node.children.map((lastChild, index) => {
24+
const firstChild = node.firstChildren[index];
25+
const mergedChild: UpdateTreeNode = {
26+
...lastChild,
27+
type: "group",
28+
firstUpdate: firstChild.update,
29+
firstChildren: firstChild.children,
30+
count: node.count,
31+
};
32+
return mergedChild;
33+
});
34+
} else {
35+
childrenToRender = node.children;
36+
}
37+
2038
return (
2139
<div className="tree-node">
2240
<div className="tree-node-content">
@@ -41,7 +59,7 @@ export function UpdateTreeNodeComponent({ node }: UpdateTreeNodeProps) {
4159

4260
{hasChildren && !isCollapsed.value && (
4361
<div className="tree-children">
44-
{node.children.map(child => (
62+
{childrenToRender.map(child => (
4563
<UpdateTreeNodeComponent key={child.id} node={child} />
4664
))}
4765
</div>

extension/src/models/UpdatesModel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface UpdateTreeNodeGroup extends UpdateTreeNodeBase {
1818
type: "group";
1919
count: number;
2020
firstUpdate: SignalUpdate;
21+
firstChildren: UpdateTreeNode[];
2122
}
2223

2324
export type UpdateTreeNode = UpdateTreeNodeGroup | UpdateTreeNodeSingle;
@@ -44,11 +45,13 @@ const collapseTree = (nodes: UpdateTreeNodeSingle[]): UpdateTreeNode[] => {
4445
type: "group",
4546
count: 2,
4647
firstUpdate: node.update,
48+
firstChildren: node.children,
4749
};
4850
tree.push(lastNode);
4951
} else {
5052
lastNode.count++;
5153
lastNode.firstUpdate = node.update;
54+
lastNode.firstChildren = node.children;
5255
}
5356
// If the current node is equal to the last one, skip it
5457
continue;

0 commit comments

Comments
 (0)