Include ReactDebugTool from inside __DEV__ to save 1.5KB (#8322)
Benoit Girard committed
Nov 22, 2016 at 16:08 UTC
9da0bf53f78d06c65274fc039a6cfc3bd9d8b424
3 files changed
+370
-358
src/renderers/shared/ReactDebugTool.js
+331
-326
@@ -63,357 +63,362 @@ type HistoryItem = {
63
64
export type FlushHistory = Array<HistoryItem>;
65
66
-var hooks = [];
67
-var didHookThrowForEvent = {};
68
-
69
-function callHook(event, fn, context, arg1, arg2, arg3, arg4, arg5) {
70
- try {
71
- fn.call(context, arg1, arg2, arg3, arg4, arg5);
72
- } catch (e) {
73
- warning(
74
- didHookThrowForEvent[event],
75
- 'Exception thrown by hook while handling %s: %s',
76
- event,
77
- e + '\n' + e.stack
78
- );
79
- didHookThrowForEvent[event] = true;
80
- }
81
-}
66
+// Trust the developer to only use this with a __DEV__ check
67
+var ReactDebugTool = ((null: any): typeof ReactDebugTool);
68
+
69
+if (__DEV__) {
70
+ var hooks = [];
71
+ var didHookThrowForEvent = {};
72
+
73
+ const callHook = function(event, fn, context, arg1, arg2, arg3, arg4, arg5) {
74
+ try {
75
+ fn.call(context, arg1, arg2, arg3, arg4, arg5);
76
+ } catch (e) {
77
+ warning(
78
+ didHookThrowForEvent[event],
79
+ 'Exception thrown by hook while handling %s: %s',
80
+ event,
81
+ e + '\n' + e.stack
82
+ );
83
+ didHookThrowForEvent[event] = true;
84
+ }
85
+ };
86
83
-function emitEvent(event, arg1, arg2, arg3, arg4, arg5) {
84
- for (var i = 0; i < hooks.length; i++) {
85
- var hook = hooks[i];
86
- var fn = hook[event];
87
- if (fn) {
88
- callHook(event, fn, hook, arg1, arg2, arg3, arg4, arg5);
87
+ const emitEvent = function(event, arg1, arg2, arg3, arg4, arg5) {
88
+ for (var i = 0; i < hooks.length; i++) {
89
+ var hook = hooks[i];
90
+ var fn = hook[event];
91
+ if (fn) {
92
+ callHook(event, fn, hook, arg1, arg2, arg3, arg4, arg5);
93
+ }
94
}
90
- }
91
-}
95
+ };
96
93
-var isProfiling = false;
94
-var flushHistory = [];
95
-var lifeCycleTimerStack = [];
96
-var currentFlushNesting = 0;
97
-var currentFlushMeasurements = [];
98
-var currentFlushStartTime = 0;
99
-var currentTimerDebugID = null;
100
-var currentTimerStartTime = 0;
101
-var currentTimerNestedFlushDuration = 0;
102
-var currentTimerType = null;
103
-
104
-var lifeCycleTimerHasWarned = false;
105
-
106
-function clearHistory() {
107
- ReactComponentTreeHook.purgeUnmountedComponents();
108
- ReactHostOperationHistoryHook.clearHistory();
109
-}
97
+ var isProfiling = false;
98
+ var flushHistory = [];
99
+ var lifeCycleTimerStack = [];
100
+ var currentFlushNesting = 0;
101
+ var currentFlushMeasurements = [];
102
+ var currentFlushStartTime = 0;
103
+ var currentTimerDebugID = null;
104
+ var currentTimerStartTime = 0;
105
+ var currentTimerNestedFlushDuration = 0;
106
+ var currentTimerType = null;
107
+
108
+ var lifeCycleTimerHasWarned = false;
109
+
110
+ const clearHistory = function() {
111
+ ReactComponentTreeHook.purgeUnmountedComponents();
112
+ ReactHostOperationHistoryHook.clearHistory();
113
+ };
114
111
-function getTreeSnapshot(registeredIDs) {
112
- return registeredIDs.reduce((tree, id) => {
113
- var ownerID = ReactComponentTreeHook.getOwnerID(id);
114
- var parentID = ReactComponentTreeHook.getParentID(id);
115
- tree[id] = {
116
- displayName: ReactComponentTreeHook.getDisplayName(id),
117
- text: ReactComponentTreeHook.getText(id),
118
- updateCount: ReactComponentTreeHook.getUpdateCount(id),
119
- childIDs: ReactComponentTreeHook.getChildIDs(id),
120
- // Text nodes don't have owners but this is close enough.
121
- ownerID: ownerID ||
122
- parentID && ReactComponentTreeHook.getOwnerID(parentID) ||
123
- 0,
124
- parentID,
125
- };
126
- return tree;
127
- }, {});
128
-}
115
+ const getTreeSnapshot = function(registeredIDs) {
116
+ return registeredIDs.reduce((tree, id) => {
117
+ var ownerID = ReactComponentTreeHook.getOwnerID(id);
118
+ var parentID = ReactComponentTreeHook.getParentID(id);
119
+ tree[id] = {
120
+ displayName: ReactComponentTreeHook.getDisplayName(id),
121
+ text: ReactComponentTreeHook.getText(id),
122
+ updateCount: ReactComponentTreeHook.getUpdateCount(id),
123
+ childIDs: ReactComponentTreeHook.getChildIDs(id),
124
+ // Text nodes don't have owners but this is close enough.
125
+ ownerID: ownerID ||
126
+ parentID && ReactComponentTreeHook.getOwnerID(parentID) ||
127
+ 0,
128
+ parentID,
129
+ };
130
+ return tree;
131
+ }, {});
132
+ };
133
130
-function resetMeasurements() {
131
- var previousStartTime = currentFlushStartTime;
132
- var previousMeasurements = currentFlushMeasurements;
133
- var previousOperations = ReactHostOperationHistoryHook.getHistory();
134
+ const resetMeasurements = function() {
135
+ var previousStartTime = currentFlushStartTime;
136
+ var previousMeasurements = currentFlushMeasurements;
137
+ var previousOperations = ReactHostOperationHistoryHook.getHistory();
138
135
- if (currentFlushNesting === 0) {
136
- currentFlushStartTime = 0;
137
- currentFlushMeasurements = [];
138
- clearHistory();
139
- return;
140
- }
139
+ if (currentFlushNesting === 0) {
140
+ currentFlushStartTime = 0;
141
+ currentFlushMeasurements = [];
142
+ clearHistory();
143
+ return;
144
+ }
145
142
- if (previousMeasurements.length || previousOperations.length) {
143
- var registeredIDs = ReactComponentTreeHook.getRegisteredIDs();
144
- flushHistory.push({
145
- duration: performanceNow() - previousStartTime,
146
- measurements: previousMeasurements || [],
147
- operations: previousOperations || [],
148
- treeSnapshot: getTreeSnapshot(registeredIDs),
149
- });
150
- }
146
+ if (previousMeasurements.length || previousOperations.length) {
147
+ var registeredIDs = ReactComponentTreeHook.getRegisteredIDs();
148
+ flushHistory.push({
149
+ duration: performanceNow() - previousStartTime,
150
+ measurements: previousMeasurements || [],
151
+ operations: previousOperations || [],
152
+ treeSnapshot: getTreeSnapshot(registeredIDs),
153
+ });
154
+ }
155
152
- clearHistory();
153
- currentFlushStartTime = performanceNow();
154
- currentFlushMeasurements = [];
155
-}
156
+ clearHistory();
157
+ currentFlushStartTime = performanceNow();
158
+ currentFlushMeasurements = [];
159
+ };
160
157
-function checkDebugID(debugID, allowRoot = false) {
158
- if (allowRoot && debugID === 0) {
159
- return;
160
- }
161
- if (!debugID) {
162
- warning(false, 'ReactDebugTool: debugID may not be empty.');
163
- }
164
-}
161
+ const checkDebugID = function(debugID, allowRoot = false) {
162
+ if (allowRoot && debugID === 0) {
163
+ return;
164
+ }
165
+ if (!debugID) {
166
+ warning(false, 'ReactDebugTool: debugID may not be empty.');
167
+ }
168
+ };
169
166
-function beginLifeCycleTimer(debugID, timerType) {
167
- if (currentFlushNesting === 0) {
168
- return;
169
- }
170
- if (currentTimerType && !lifeCycleTimerHasWarned) {
171
- warning(
172
- false,
173
- 'There is an internal error in the React performance measurement code. ' +
174
- 'Did not expect %s timer to start while %s timer is still in ' +
175
- 'progress for %s instance.',
176
- timerType,
177
- currentTimerType || 'no',
178
- (debugID === currentTimerDebugID) ? 'the same' : 'another'
179
- );
180
- lifeCycleTimerHasWarned = true;
181
- }
182
- currentTimerStartTime = performanceNow();
183
- currentTimerNestedFlushDuration = 0;
184
- currentTimerDebugID = debugID;
185
- currentTimerType = timerType;
186
-}
170
+ const beginLifeCycleTimer = function(debugID, timerType) {
171
+ if (currentFlushNesting === 0) {
172
+ return;
173
+ }
174
+ if (currentTimerType && !lifeCycleTimerHasWarned) {
175
+ warning(
176
+ false,
177
+ 'There is an internal error in the React performance measurement code. ' +
178
+ 'Did not expect %s timer to start while %s timer is still in ' +
179
+ 'progress for %s instance.',
180
+ timerType,
181
+ currentTimerType || 'no',
182
+ (debugID === currentTimerDebugID) ? 'the same' : 'another'
183
+ );
184
+ lifeCycleTimerHasWarned = true;
185
+ }
186
+ currentTimerStartTime = performanceNow();
187
+ currentTimerNestedFlushDuration = 0;
188
+ currentTimerDebugID = debugID;
189
+ currentTimerType = timerType;
190
+ };
191
188
-function endLifeCycleTimer(debugID, timerType) {
189
- if (currentFlushNesting === 0) {
190
- return;
191
- }
192
- if (currentTimerType !== timerType && !lifeCycleTimerHasWarned) {
193
- warning(
194
- false,
195
- 'There is an internal error in the React performance measurement code. ' +
196
- 'We did not expect %s timer to stop while %s timer is still in ' +
197
- 'progress for %s instance. Please report this as a bug in React.',
198
- timerType,
199
- currentTimerType || 'no',
200
- (debugID === currentTimerDebugID) ? 'the same' : 'another'
201
- );
202
- lifeCycleTimerHasWarned = true;
203
- }
204
- if (isProfiling) {
205
- currentFlushMeasurements.push({
206
- timerType,
207
- instanceID: debugID,
208
- duration: performanceNow() - currentTimerStartTime - currentTimerNestedFlushDuration,
209
- });
210
- }
211
- currentTimerStartTime = 0;
212
- currentTimerNestedFlushDuration = 0;
213
- currentTimerDebugID = null;
214
- currentTimerType = null;
215
-}
192
+ const endLifeCycleTimer = function(debugID, timerType) {
193
+ if (currentFlushNesting === 0) {
194
+ return;
195
+ }
196
+ if (currentTimerType !== timerType && !lifeCycleTimerHasWarned) {
197
+ warning(
198
+ false,
199
+ 'There is an internal error in the React performance measurement code. ' +
200
+ 'We did not expect %s timer to stop while %s timer is still in ' +
201
+ 'progress for %s instance. Please report this as a bug in React.',
202
+ timerType,
203
+ currentTimerType || 'no',
204
+ (debugID === currentTimerDebugID) ? 'the same' : 'another'
205
+ );
206
+ lifeCycleTimerHasWarned = true;
207
+ }
208
+ if (isProfiling) {
209
+ currentFlushMeasurements.push({
210
+ timerType,
211
+ instanceID: debugID,
212
+ duration: performanceNow() - currentTimerStartTime - currentTimerNestedFlushDuration,
213
+ });
214
+ }
215
+ currentTimerStartTime = 0;
216
+ currentTimerNestedFlushDuration = 0;
217
+ currentTimerDebugID = null;
218
+ currentTimerType = null;
219
+ };
220
217
-function pauseCurrentLifeCycleTimer() {
218
- var currentTimer = {
219
- startTime: currentTimerStartTime,
220
- nestedFlushStartTime: performanceNow(),
221
- debugID: currentTimerDebugID,
222
- timerType: currentTimerType,
221
+ const pauseCurrentLifeCycleTimer = function() {
222
+ var currentTimer = {
223
+ startTime: currentTimerStartTime,
224
+ nestedFlushStartTime: performanceNow(),
225
+ debugID: currentTimerDebugID,
226
+ timerType: currentTimerType,
227
+ };
228
+ lifeCycleTimerStack.push(currentTimer);
229
+ currentTimerStartTime = 0;
230
+ currentTimerNestedFlushDuration = 0;
231
+ currentTimerDebugID = null;
232
+ currentTimerType = null;
233
};
224
- lifeCycleTimerStack.push(currentTimer);
225
- currentTimerStartTime = 0;
226
- currentTimerNestedFlushDuration = 0;
227
- currentTimerDebugID = null;
228
- currentTimerType = null;
229
-}
234
231
-function resumeCurrentLifeCycleTimer() {
232
- var {startTime, nestedFlushStartTime, debugID, timerType} = lifeCycleTimerStack.pop();
233
- var nestedFlushDuration = performanceNow() - nestedFlushStartTime;
234
- currentTimerStartTime = startTime;
235
- currentTimerNestedFlushDuration += nestedFlushDuration;
236
- currentTimerDebugID = debugID;
237
- currentTimerType = timerType;
238
-}
235
+ const resumeCurrentLifeCycleTimer = function() {
236
+ var {startTime, nestedFlushStartTime, debugID, timerType} = lifeCycleTimerStack.pop();
237
+ var nestedFlushDuration = performanceNow() - nestedFlushStartTime;
238
+ currentTimerStartTime = startTime;
239
+ currentTimerNestedFlushDuration += nestedFlushDuration;
240
+ currentTimerDebugID = debugID;
241
+ currentTimerType = timerType;
242
+ };
243
240
-var lastMarkTimeStamp = 0;
241
-var canUsePerformanceMeasure: boolean =
242
- typeof performance !== 'undefined' &&
243
- typeof performance.mark === 'function' &&
244
- typeof performance.clearMarks === 'function' &&
245
- typeof performance.measure === 'function' &&
246
- typeof performance.clearMeasures === 'function';
247
-
248
-function shouldMark(debugID) {
249
- if (!isProfiling || !canUsePerformanceMeasure) {
250
- return false;
251
- }
252
- var element = ReactComponentTreeHook.getElement(debugID);
253
- if (element == null || typeof element !== 'object') {
254
- return false;
255
- }
256
- var isHostElement = typeof element.type === 'string';
257
- if (isHostElement) {
258
- return false;
259
- }
260
- return true;
261
-}
244
+ var lastMarkTimeStamp = 0;
245
+ var canUsePerformanceMeasure: boolean =
246
+ typeof performance !== 'undefined' &&
247
+ typeof performance.mark === 'function' &&
248
+ typeof performance.clearMarks === 'function' &&
249
+ typeof performance.measure === 'function' &&
250
+ typeof performance.clearMeasures === 'function';
251
+
252
+ const shouldMark = function(debugID) {
253
+ if (!isProfiling || !canUsePerformanceMeasure) {
254
+ return false;
255
+ }
256
+ var element = ReactComponentTreeHook.getElement(debugID);
257
+ if (element == null || typeof element !== 'object') {
258
+ return false;
259
+ }
260
+ var isHostElement = typeof element.type === 'string';
261
+ if (isHostElement) {
262
+ return false;
263
+ }
264
+ return true;
265
+ };
266
263
-function markBegin(debugID, markType) {
264
- if (!shouldMark(debugID)) {
265
- return;
266
- }
267
+ const markBegin = function(debugID, markType) {
268
+ if (!shouldMark(debugID)) {
269
+ return;
270
+ }
271
268
- var markName = `${debugID}::${markType}`;
269
- lastMarkTimeStamp = performanceNow();
270
- performance.mark(markName);
271
-}
272
+ var markName = `${debugID}::${markType}`;
273
+ lastMarkTimeStamp = performanceNow();
274
+ performance.mark(markName);
275
+ };
276
273
-function markEnd(debugID, markType) {
274
- if (!shouldMark(debugID)) {
275
- return;
276
- }
277
+ const markEnd = function(debugID, markType) {
278
+ if (!shouldMark(debugID)) {
279
+ return;
280
+ }
281
278
- var markName = `${debugID}::${markType}`;
279
- var displayName = ReactComponentTreeHook.getDisplayName(debugID) || 'Unknown';
280
-
281
- // Chrome has an issue of dropping markers recorded too fast:
282
- // https://bugs.chromium.org/p/chromium/issues/detail?id=640652
283
- // To work around this, we will not report very small measurements.
284
- // I determined the magic number by tweaking it back and forth.
285
- // 0.05ms was enough to prevent the issue, but I set it to 0.1ms to be safe.
286
- // When the bug is fixed, we can `measure()` unconditionally if we want to.
287
- var timeStamp = performanceNow();
288
- if (timeStamp - lastMarkTimeStamp > 0.1) {
289
- var measurementName = `${displayName} [${markType}]`;
290
- performance.measure(measurementName, markName);
291
- }
282
+ var markName = `${debugID}::${markType}`;
283
+ var displayName = ReactComponentTreeHook.getDisplayName(debugID) || 'Unknown';
284
+
285
+ // Chrome has an issue of dropping markers recorded too fast:
286
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=640652
287
+ // To work around this, we will not report very small measurements.
288
+ // I determined the magic number by tweaking it back and forth.
289
+ // 0.05ms was enough to prevent the issue, but I set it to 0.1ms to be safe.
290
+ // When the bug is fixed, we can `measure()` unconditionally if we want to.
291
+ var timeStamp = performanceNow();
292
+ if (timeStamp - lastMarkTimeStamp > 0.1) {
293
+ var measurementName = `${displayName} [${markType}]`;
294
+ performance.measure(measurementName, markName);
295
+ }
296
293
- performance.clearMarks(markName);
294
- performance.clearMeasures(measurementName);
295
-}
297
+ performance.clearMarks(markName);
298
+ performance.clearMeasures(measurementName);
299
+ };
300
297
-var ReactDebugTool = {
298
- addHook(hook: Hook): void {
299
- hooks.push(hook);
300
- },
301
- removeHook(hook: Hook): void {
302
- for (var i = 0; i < hooks.length; i++) {
303
- if (hooks[i] === hook) {
304
- hooks.splice(i, 1);
305
- i--;
301
+ ReactDebugTool = {
302
+ addHook(hook: Hook): void {
303
+ hooks.push(hook);
304
+ },
305
+ removeHook(hook: Hook): void {
306
+ for (var i = 0; i < hooks.length; i++) {
307
+ if (hooks[i] === hook) {
308
+ hooks.splice(i, 1);
309
+ i--;
310
+ }
311
+ }
312
+ },
313
+ isProfiling(): boolean {
314
+ return isProfiling;
315
+ },
316
+ beginProfiling(): void {
317
+ if (isProfiling) {
318
+ return;
319
}
307
- }
308
- },
309
- isProfiling(): boolean {
310
- return isProfiling;
311
- },
312
- beginProfiling(): void {
313
- if (isProfiling) {
314
- return;
315
- }
320
317
- isProfiling = true;
318
- flushHistory.length = 0;
319
- resetMeasurements();
320
- ReactDebugTool.addHook(ReactHostOperationHistoryHook);
321
- },
322
- endProfiling(): void {
323
- if (!isProfiling) {
324
- return;
325
- }
321
+ isProfiling = true;
322
+ flushHistory.length = 0;
323
+ resetMeasurements();
324
+ ReactDebugTool.addHook(ReactHostOperationHistoryHook);
325
+ },
326
+ endProfiling(): void {
327
+ if (!isProfiling) {
328
+ return;
329
+ }
330
327
- isProfiling = false;
328
- resetMeasurements();
329
- ReactDebugTool.removeHook(ReactHostOperationHistoryHook);
330
- },
331
- getFlushHistory(): FlushHistory {
332
- return flushHistory;
333
- },
334
- onBeginFlush(): void {
335
- currentFlushNesting++;
336
- resetMeasurements();
337
- pauseCurrentLifeCycleTimer();
338
- emitEvent('onBeginFlush');
339
- },
340
- onEndFlush(): void {
341
- resetMeasurements();
342
- currentFlushNesting--;
343
- resumeCurrentLifeCycleTimer();
344
- emitEvent('onEndFlush');
345
- },
346
- onBeginLifeCycleTimer(debugID: DebugID, timerType: TimerType): void {
347
- checkDebugID(debugID);
348
- emitEvent('onBeginLifeCycleTimer', debugID, timerType);
349
- markBegin(debugID, timerType);
350
- beginLifeCycleTimer(debugID, timerType);
351
- },
352
- onEndLifeCycleTimer(debugID: DebugID, timerType: TimerType): void {
353
- checkDebugID(debugID);
354
- endLifeCycleTimer(debugID, timerType);
355
- markEnd(debugID, timerType);
356
- emitEvent('onEndLifeCycleTimer', debugID, timerType);
357
- },
358
- onBeginProcessingChildContext(): void {
359
- emitEvent('onBeginProcessingChildContext');
360
- },
361
- onEndProcessingChildContext(): void {
362
- emitEvent('onEndProcessingChildContext');
363
- },
364
- onHostOperation(operation: Operation) {
365
- checkDebugID(operation.instanceID);
366
- emitEvent('onHostOperation', operation);
367
- },
368
- onSetState(): void {
369
- emitEvent('onSetState');
370
- },
371
- onSetChildren(debugID: DebugID, childDebugIDs: Array<DebugID>) {
372
- checkDebugID(debugID);
373
- childDebugIDs.forEach(checkDebugID);
374
- emitEvent('onSetChildren', debugID, childDebugIDs);
375
- },
376
- onBeforeMountComponent(debugID: DebugID, element: ReactElement, parentDebugID: DebugID): void {
377
- checkDebugID(debugID);
378
- checkDebugID(parentDebugID, true);
379
- emitEvent('onBeforeMountComponent', debugID, element, parentDebugID);
380
- markBegin(debugID, 'mount');
381
- },
382
- onMountComponent(debugID: DebugID): void {
383
- checkDebugID(debugID);
384
- markEnd(debugID, 'mount');
385
- emitEvent('onMountComponent', debugID);
386
- },
387
- onBeforeUpdateComponent(debugID: DebugID, element: ReactElement): void {
388
- checkDebugID(debugID);
389
- emitEvent('onBeforeUpdateComponent', debugID, element);
390
- markBegin(debugID, 'update');
391
- },
392
- onUpdateComponent(debugID: DebugID): void {
393
- checkDebugID(debugID);
394
- markEnd(debugID, 'update');
395
- emitEvent('onUpdateComponent', debugID);
396
- },
397
- onBeforeUnmountComponent(debugID: DebugID): void {
398
- checkDebugID(debugID);
399
- emitEvent('onBeforeUnmountComponent', debugID);
400
- markBegin(debugID, 'unmount');
401
- },
402
- onUnmountComponent(debugID: DebugID): void {
403
- checkDebugID(debugID);
404
- markEnd(debugID, 'unmount');
405
- emitEvent('onUnmountComponent', debugID);
406
- },
407
- onTestEvent(): void {
408
- emitEvent('onTestEvent');
409
- },
410
-};
331
+ isProfiling = false;
332
+ resetMeasurements();
333
+ ReactDebugTool.removeHook(ReactHostOperationHistoryHook);
334
+ },
335
+ getFlushHistory(): FlushHistory {
336
+ return flushHistory;
337
+ },
338
+ onBeginFlush(): void {
339
+ currentFlushNesting++;
340
+ resetMeasurements();
341
+ pauseCurrentLifeCycleTimer();
342
+ emitEvent('onBeginFlush');
343
+ },
344
+ onEndFlush(): void {
345
+ resetMeasurements();
346
+ currentFlushNesting--;
347
+ resumeCurrentLifeCycleTimer();
348
+ emitEvent('onEndFlush');
349
+ },
350
+ onBeginLifeCycleTimer(debugID: DebugID, timerType: TimerType): void {
351
+ checkDebugID(debugID);
352
+ emitEvent('onBeginLifeCycleTimer', debugID, timerType);
353
+ markBegin(debugID, timerType);
354
+ beginLifeCycleTimer(debugID, timerType);
355
+ },
356
+ onEndLifeCycleTimer(debugID: DebugID, timerType: TimerType): void {
357
+ checkDebugID(debugID);
358
+ endLifeCycleTimer(debugID, timerType);
359
+ markEnd(debugID, timerType);
360
+ emitEvent('onEndLifeCycleTimer', debugID, timerType);
361
+ },
362
+ onBeginProcessingChildContext(): void {
363
+ emitEvent('onBeginProcessingChildContext');
364
+ },
365
+ onEndProcessingChildContext(): void {
366
+ emitEvent('onEndProcessingChildContext');
367
+ },
368
+ onHostOperation(operation: Operation) {
369
+ checkDebugID(operation.instanceID);
370
+ emitEvent('onHostOperation', operation);
371
+ },
372
+ onSetState(): void {
373
+ emitEvent('onSetState');
374
+ },
375
+ onSetChildren(debugID: DebugID, childDebugIDs: Array<DebugID>) {
376
+ checkDebugID(debugID);
377
+ childDebugIDs.forEach(checkDebugID);
378
+ emitEvent('onSetChildren', debugID, childDebugIDs);
379
+ },
380
+ onBeforeMountComponent(debugID: DebugID, element: ReactElement, parentDebugID: DebugID): void {
381
+ checkDebugID(debugID);
382
+ checkDebugID(parentDebugID, true);
383
+ emitEvent('onBeforeMountComponent', debugID, element, parentDebugID);
384
+ markBegin(debugID, 'mount');
385
+ },
386
+ onMountComponent(debugID: DebugID): void {
387
+ checkDebugID(debugID);
388
+ markEnd(debugID, 'mount');
389
+ emitEvent('onMountComponent', debugID);
390
+ },
391
+ onBeforeUpdateComponent(debugID: DebugID, element: ReactElement): void {
392
+ checkDebugID(debugID);
393
+ emitEvent('onBeforeUpdateComponent', debugID, element);
394
+ markBegin(debugID, 'update');
395
+ },
396
+ onUpdateComponent(debugID: DebugID): void {
397
+ checkDebugID(debugID);
398
+ markEnd(debugID, 'update');
399
+ emitEvent('onUpdateComponent', debugID);
400
+ },
401
+ onBeforeUnmountComponent(debugID: DebugID): void {
402
+ checkDebugID(debugID);
403
+ emitEvent('onBeforeUnmountComponent', debugID);
404
+ markBegin(debugID, 'unmount');
405
+ },
406
+ onUnmountComponent(debugID: DebugID): void {
407
+ checkDebugID(debugID);
408
+ markEnd(debugID, 'unmount');
409
+ emitEvent('onUnmountComponent', debugID);
410
+ },
411
+ onTestEvent(): void {
412
+ emitEvent('onTestEvent');
413
+ },
414
+ };
415
412
-ReactDebugTool.addHook(ReactInvalidSetStateWarningHook);
413
-ReactDebugTool.addHook(ReactComponentTreeHook);
414
-var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
415
-if ((/[?&]react_perf\b/).test(url)) {
416
- ReactDebugTool.beginProfiling();
416
+ ReactDebugTool.addHook(ReactInvalidSetStateWarningHook);
417
+ ReactDebugTool.addHook(ReactComponentTreeHook);
418
+ var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
419
+ if ((/[?&]react_perf\b/).test(url)) {
420
+ ReactDebugTool.beginProfiling();
421
+ }
422
}
423
424
module.exports = ReactDebugTool;
src/renderers/shared/hooks/ReactHostOperationHistoryHook.js
+25
-20
@@ -26,25 +26,30 @@ export type Operation = {instanceID: DebugID} & (
26
{type: 'remove attribute', payload: string}
27
);
28
29
-var history: Array<Operation> = [];
30
-
31
-var ReactHostOperationHistoryHook = {
32
- onHostOperation(operation: Operation) {
33
- history.push(operation);
34
- },
35
-
36
- clearHistory(): void {
37
- if (ReactHostOperationHistoryHook._preventClearing) {
38
- // Should only be used for tests.
39
- return;
40
- }
41
-
42
- history = [];
43
- },
44
-
45
- getHistory(): Array<Operation> {
46
- return history;
47
- },
48
-};
29
+// Trust the developer to only use this with a __DEV__ check
30
+var ReactHostOperationHistoryHook = ((null: any): typeof ReactHostOperationHistoryHook);
31
+
32
+if (__DEV__) {
33
+ var history: Array<Operation> = [];
34
+
35
+ ReactHostOperationHistoryHook = {
36
+ onHostOperation(operation: Operation) {
37
+ history.push(operation);
38
+ },
39
+
40
+ clearHistory(): void {
41
+ if (ReactHostOperationHistoryHook._preventClearing) {
42
+ // Should only be used for tests.
43
+ return;
44
+ }
45
+
46
+ history = [];
47
+ },
48
+
49
+ getHistory(): Array<Operation> {
50
+ return history;
51
+ },
52
+ };
53
+}
54
55
module.exports = ReactHostOperationHistoryHook;
src/renderers/shared/hooks/ReactInvalidSetStateWarningHook.js
+14
-12
@@ -14,6 +14,8 @@
14
15
var warning = require('warning');
16
17
+var ReactInvalidSetStateWarningHook = {};
18
+
19
if (__DEV__) {
20
var processingChildContext = false;
21
@@ -23,18 +25,18 @@ if (__DEV__) {
25
'setState(...): Cannot call setState() inside getChildContext()'
26
);
27
};
26
-}
28
28
-var ReactInvalidSetStateWarningHook = {
29
- onBeginProcessingChildContext(): void {
30
- processingChildContext = true;
31
- },
32
- onEndProcessingChildContext(): void {
33
- processingChildContext = false;
34
- },
35
- onSetState(): void {
36
- warnInvalidSetState();
37
- },
38
-};
29
+ ReactInvalidSetStateWarningHook = {
30
+ onBeginProcessingChildContext(): void {
31
+ processingChildContext = true;
32
+ },
33
+ onEndProcessingChildContext(): void {
34
+ processingChildContext = false;
35
+ },
36
+ onSetState(): void {
37
+ warnInvalidSetState();
38
+ },
39
+ };
40
+}
41
42
module.exports = ReactInvalidSetStateWarningHook;