@samitouri / QOS-React / commits / 89f4955b93

Don't show roots in Elements tree

Brian Vaughn committed Jan 31, 2019 at 14:31 UTC 89f4955b9335d2ec025c5ca6ad71f2b69ba03697
1 file changed +9 -5
src/devtools/store.js
+9 -5
@@ -43,6 +43,8 @@ export default class Store extends EventEmitter {
43 constructor(bridge: Bridge) {
44 super();
45
46 + debug('constructor', 'subscribing to Bridge');
47 +
48 bridge.on('operations', this.onBridgeOperations);
49 bridge.on('rootCommitted', this.onBridgeRootCommitted);
50 }
@@ -78,8 +80,10 @@ export default class Store extends EventEmitter {
80 }
81 }
82
81 - // Crawl the tree to find the correct root...
82 - let currentElement = ((root: any): Element);
83 + // Find the element in the tree using the weight of each node...
84 + // Skip over the root itself, because roots aren't visible in the Elements tree.
85 + const firstChildID = ((root: any): Element).children[0];
86 + let currentElement = ((this._idToElement.get(firstChildID): any): Element);
87 let currentWeight = 0;
88 while (index !== currentWeight) {
89 for (let i = 0; i < currentElement.children.length; i++) {
@@ -145,13 +149,13 @@ export default class Store extends EventEmitter {
149
150 this._idToElement.set(id, {
151 children: [],
148 - depth: 0,
152 + depth: -1,
153 displayName: null,
154 id,
155 key: null,
156 parentID: 0,
157 type,
154 - weight: 1,
158 + weight: 0,
159 });
160
161 haveRootsChanged = true;
@@ -283,7 +287,7 @@ export default class Store extends EventEmitter {
287 const printElement = (id: number) => {
288 const element = ((this._idToElement.get(id): any): Element);
289 console.log(
286 - `${' '.repeat(element.depth)}${element.id}:${element.displayName ||
290 + `${'•'.repeat(element.depth)}${element.id}:${element.displayName ||
291 ''}${element.key ? `key:"${element.key}"` : ''} (${element.weight})`
292 );
293 element.children.forEach(printElement);