Log the updateQueue in dumpTree
This also buffers all rows into a single console.log call. This is because jest nows adds the line number of each console.log call which becomes quite noisy for these trees.
Sebastian Markbage committed
Sep 5, 2016 at 23:05 UTC
27d1210c1d00e9b34839fd5596a74d8af52ffa7f
1 file changed
+41
-7
src/renderers/noop/ReactNoop.js
+41
-7
@@ -20,6 +20,7 @@
20
'use strict';
21
22
import type { Fiber } from 'ReactFiber';
23
+import type { UpdateQueue } from 'ReactFiberUpdateQueue';
24
import type { HostChildren } from 'ReactFiberReconciler';
25
26
var ReactFiberReconciler = require('ReactFiberReconciler');
@@ -153,30 +154,61 @@ var ReactNoop = {
154
return;
155
}
156
157
+ var bufferedLog = [];
158
+ function log(...args) {
159
+ bufferedLog.push(...args, '\n');
160
+ }
161
+
162
function logHostInstances(children: Array<Instance>, depth) {
163
for (var i = 0; i < children.length; i++) {
164
var child = children[i];
159
- console.log(' '.repeat(depth) + '- ' + child.type + '#' + child.id);
165
+ log(' '.repeat(depth) + '- ' + child.type + '#' + child.id);
166
logHostInstances(child.children, depth + 1);
167
}
168
}
169
function logContainer(container : Container, depth) {
164
- console.log(' '.repeat(depth) + '- [root#' + container.rootID + ']');
170
+ log(' '.repeat(depth) + '- [root#' + container.rootID + ']');
171
logHostInstances(container.children, depth + 1);
172
}
173
174
+ function logUpdateQueue(updateQueue : UpdateQueue, depth) {
175
+ log(
176
+ ' '.repeat(depth + 1) + 'QUEUED UPDATES',
177
+ updateQueue.isReplace ? 'is replace' : '',
178
+ updateQueue.isForced ? 'is forced' : ''
179
+ );
180
+ log(
181
+ ' '.repeat(depth + 1) + '~',
182
+ updateQueue.partialState,
183
+ updateQueue.callback ? 'with callback' : ''
184
+ );
185
+ var next;
186
+ while (next = updateQueue.next) {
187
+ log(
188
+ ' '.repeat(depth + 1) + '~',
189
+ next.partialState,
190
+ next.callback ? 'with callback' : ''
191
+ );
192
+ }
193
+ }
194
+
195
function logFiber(fiber : Fiber, depth) {
169
- console.log(
196
+ log(
197
' '.repeat(depth) + '- ' + (fiber.type ? fiber.type.name || fiber.type : '[root]'),
198
'[' + fiber.pendingWorkPriority + (fiber.pendingProps ? '*' : '') + ']'
199
);
200
+ if (fiber.updateQueue) {
201
+ logUpdateQueue(fiber.updateQueue, depth);
202
+ }
203
const childInProgress = fiber.progressedChild;
204
if (childInProgress && childInProgress !== fiber.child) {
175
- console.log(' '.repeat(depth + 1) + 'IN PROGRESS: ' + fiber.progressedPriority);
205
+ log(' '.repeat(depth + 1) + 'IN PROGRESS: ' + fiber.progressedPriority);
206
logFiber(childInProgress, depth + 1);
207
if (fiber.child) {
178
- console.log(' '.repeat(depth + 1) + 'CURRENT');
208
+ log(' '.repeat(depth + 1) + 'CURRENT');
209
}
210
+ } else if (fiber.child && fiber.updateQueue) {
211
+ log(' '.repeat(depth + 1) + 'CHILDREN');
212
}
213
if (fiber.child) {
214
logFiber(fiber.child, depth + 1);
@@ -186,10 +218,12 @@ var ReactNoop = {
218
}
219
}
220
189
- console.log('HOST INSTANCES:');
221
+ log('HOST INSTANCES:');
222
logContainer(rootContainer, 0);
191
- console.log('FIBERS:');
223
+ log('FIBERS:');
224
logFiber((root.stateNode : any).current, 0);
225
+
226
+ console.log(...bufferedLog);
227
},
228
229
};