From ba7275dc4fb6e21f44977bfe09c5432af868bd9e Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Mon, 26 Jun 2017 09:16:35 -0400 Subject: [PATCH] Dump the tree structure to a string for debugging --- src/native-watcher-registry.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/native-watcher-registry.js b/src/native-watcher-registry.js index 9b78f5505..c3ba01d39 100644 --- a/src/native-watcher-registry.js +++ b/src/native-watcher-registry.js @@ -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