@samitouri / QOS-React / commits / 285e661757

dumpTree helper for debugging

It is helpful to be able to dump information about the current tree for debugging issues in unit tests.

Sebastian Markbage committed Jun 18, 2016 at 21:39 UTC 285e661757899efca112ae30a6e7d529abf58d54
1 file changed +31
src/renderers/noop/ReactNoop.js
+31
@@ -19,6 +19,8 @@
19
20 'use strict';
21
22 +import type { Fiber } from 'ReactFiber';
23 +
24 var ReactFiberReconciler = require('ReactFiberReconciler');
25
26 var scheduledHighPriCallback = null;
@@ -83,6 +85,35 @@ var ReactNoop = {
85 ReactNoop.flushLowPri();
86 },
87
88 + // Logs the current state of the tree.
89 + dumpTree() {
90 + if (!root) {
91 + console.log('Nothing rendered yet.');
92 + return;
93 + }
94 + let fiber : Fiber = (root.stateNode : any).current;
95 + let depth = 0;
96 + while (fiber) {
97 + console.log(' '.repeat(depth) + '- ' + (fiber.type ? fiber.type.name || fiber.type : '[root]'), '[' + fiber.pendingWorkPriority + (fiber.pendingProps ? '*' : '') + ']');
98 + if (fiber.child) {
99 + fiber = fiber.child;
100 + depth++;
101 + continue;
102 + } else {
103 + while (!fiber.sibling) {
104 + if (!fiber.parent) {
105 + return;
106 + } else {
107 + // $FlowFixMe: This downcast is not safe. It is intentionally an error.
108 + fiber = fiber.parent;
109 + }
110 + depth--;
111 + }
112 + fiber = fiber.sibling;
113 + }
114 + }
115 + },
116 +
117 };
118
119 module.exports = ReactNoop;