add visit function for snapshot

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent 29fcf03d4f
commit 52aac74fa2
2 changed files with 23 additions and 1 deletions

View File

@@ -425,4 +425,21 @@ function snapshot(
];
}
export function visit(
node: serializedNodeWithId,
onVisit: (node: serializedNodeWithId) => unknown,
) {
function walk(current: serializedNodeWithId) {
onVisit(current);
if (
current.type === NodeType.Document ||
current.type === NodeType.Element
) {
current.childNodes.forEach(walk);
}
}
walk(node);
}
export default snapshot;