Dump the tree structure to a string for debugging

This commit is contained in:
Ash Wilson
2017-06-26 09:16:35 -04:00
parent d4edc6b894
commit ba7275dc4f

View File

@@ -57,6 +57,10 @@ class RegistryTree {
return this.root
}
print () {
return this.root.print()
}
}
// Private: Non-leaf node in a tree used by the {NativeWatcherRegistry} to cover the allocated {Watcher} instances with
@@ -158,6 +162,19 @@ class RegistryNode {
}
return results
}
print (indent = 0) {
let spaces = ''
for (let i = 0; i < indent; i++) {
spaces += ' '
}
let result = ''
for (const p of Object.keys(this.children)) {
result += `${spaces}${p}\n${this.children[p].print(indent + 2)}`
}
return result
}
}
// Private: Leaf node within a {NativeWatcherRegistry} tree. Represents a directory that is covered by a
@@ -257,6 +274,20 @@ class RegistryWatcherNode {
leaves (prefix) {
return [{node: this, path: prefix}]
}
print (indent = 0) {
let result = ''
for (let i = 0; i < indent; i++) {
result += ' '
}
result += '[watcher'
if (this.childPaths.size > 0) {
result += ` +${this.childPaths.size}`
}
result += ']\n'
return result
}
}
// Private: A {RegisteryNode} traversal result that's returned when neither a directory, its children, nor its parents