114
_bridge: FrontendBridge;
115
116
// Computed whenever _errorsAndWarnings Map changes.
117
- _cachedErrorCount: number = 0;
118
- _cachedWarningCount: number = 0;
117
+ _cachedComponentWithErrorCount: number = 0;
118
+ _cachedComponentWithWarningCount: number = 0;
119
_cachedErrorAndWarningTuples: ErrorAndWarningTuples | null = null;
120
121
// Should new nodes be collapsed by default when added to the tree?
196
197
_shouldCheckBridgeProtocolCompatibility: boolean = false;
198
_hookSettings: $ReadOnly<DevToolsHookSettings> | null = null;
199
+ _shouldShowWarningsAndErrors: boolean = false;
200
201
constructor(bridge: FrontendBridge, config?: Config) {
202
super();
384
return this._bridgeProtocol;
385
}
386
386
- get errorCount(): number {
387
- return this._cachedErrorCount;
387
+ get componentWithErrorCount(): number {
388
+ if (!this._shouldShowWarningsAndErrors) {
389
+ return 0;
390
+ }
391
+
392
+ return this._cachedComponentWithErrorCount;
393
+ }
394
+
395
+ get componentWithWarningCount(): number {
396
+ if (!this._shouldShowWarningsAndErrors) {
397
+ return 0;
398
+ }
399
+
400
+ return this._cachedComponentWithWarningCount;
401
+ }
402
+
403
+ get displayingErrorsAndWarningsEnabled(): boolean {
404
+ return this._shouldShowWarningsAndErrors;
405
}
406
407
get hasOwnerMetadata(): boolean {
497
return this._unsupportedRendererVersionDetected;
498
}
499
483
- get warningCount(): number {
484
- return this._cachedWarningCount;
485
- }
486
-
500
containsElement(id: number): boolean {
501
return this._idToElement.has(id);
502
}
594
}
595
596
// Returns a tuple of [id, index]
584
- getElementsWithErrorsAndWarnings(): Array<{id: number, index: number}> {
597
+ getElementsWithErrorsAndWarnings(): ErrorAndWarningTuples {
598
+ if (!this._shouldShowWarningsAndErrors) {
599
+ return [];
600
+ }
601
+
602
if (this._cachedErrorAndWarningTuples !== null) {
603
return this._cachedErrorAndWarningTuples;
604
}
632
errorCount: number,
633
warningCount: number,
634
} {
635
+ if (!this._shouldShowWarningsAndErrors) {
636
+ return {errorCount: 0, warningCount: 0};
637
+ }
638
+
639
return this._errorsAndWarnings.get(id) || {errorCount: 0, warningCount: 0};
640
}
641
1346
this._cachedErrorAndWarningTuples = null;
1347
1348
if (haveErrorsOrWarningsChanged) {
1328
- let errorCount = 0;
1329
- let warningCount = 0;
1349
+ let componentWithErrorCount = 0;
1350
+ let componentWithWarningCount = 0;
1351
1352
this._errorsAndWarnings.forEach(entry => {
1332
- errorCount += entry.errorCount;
1333
- warningCount += entry.warningCount;
1353
+ if (entry.errorCount > 0) {
1354
+ componentWithErrorCount++;
1355
+ }
1356
+
1357
+ if (entry.warningCount > 0) {
1358
+ componentWithWarningCount++;
1359
+ }
1360
});
1361
1336
- this._cachedErrorCount = errorCount;
1337
- this._cachedWarningCount = warningCount;
1362
+ this._cachedComponentWithErrorCount = componentWithErrorCount;
1363
+ this._cachedComponentWithWarningCount = componentWithWarningCount;
1364
}
1365
1366
if (haveRootsChanged) {
1554
onHookSettings: (settings: $ReadOnly<DevToolsHookSettings>) => void =
1555
settings => {
1556
this._hookSettings = settings;
1557
+
1558
+ this.setShouldShowWarningsAndErrors(settings.showInlineWarningsAndErrors);
1559
this.emit('hookSettings', settings);
1560
};
1561
1562
+ setShouldShowWarningsAndErrors(status: boolean): void {
1563
+ const previousStatus = this._shouldShowWarningsAndErrors;
1564
+ this._shouldShowWarningsAndErrors = status;
1565
+
1566
+ if (previousStatus !== status) {
1567
+ // Propagate to subscribers, although tree state has not changed
1568
+ this.emit('mutated', [[], new Map()]);
1569
+ }
1570
+ }
1571
+
1572
// The Store should never throw an Error without also emitting an event.
1573
// Otherwise Store errors will be invisible to users,
1574
// but the downstream errors they cause will be reported as bugs.