Skip to content

Commit

Permalink
Small variable naming cleanup in Store
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Dec 22, 2020
1 parent 7e149e8 commit 5a3ae6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
29 changes: 9 additions & 20 deletions packages/react-devtools-shared/src/devtools/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class Store extends EventEmitter<{|
// Map of ID to number of recorded error and warning message IDs.
_errorsAndWarnings: Map<
number,
{errors: number, warnings: number},
{|errorCount: number, warningCount: number|},
> = new Map();

// At least one of the injected renderers contains (DEV only) owner metadata.
Expand Down Expand Up @@ -490,15 +490,7 @@ export default class Store extends EventEmitter<{|
getErrorAndWarningCountForElementID(
id: number,
): {|errorCount: number, warningCount: number|} {
const map = this._errorsAndWarnings.get(id);
if (map != null) {
return {
errorCount: map.errors,
warningCount: map.warnings,
};
} else {
return {errorCount: 0, warningCount: 0};
}
return this._errorsAndWarnings.get(id) || {errorCount: 0, warningCount: 0};
}

getIndexOfElementID(id: number): number | null {
Expand Down Expand Up @@ -1071,16 +1063,13 @@ export default class Store extends EventEmitter<{|
break;
case TREE_OPERATION_UPDATE_ERRORS_OR_WARNINGS:
const id = operations[i + 1];
const numErrors = operations[i + 2];
const numWarnings = operations[i + 3];
const errorCount = operations[i + 2];
const warningCount = operations[i + 3];

i += 4;

if (numErrors > 0 || numWarnings > 0) {
this._errorsAndWarnings.set(id, {
errors: numErrors,
warnings: numWarnings,
});
if (errorCount > 0 || warningCount > 0) {
this._errorsAndWarnings.set(id, {errorCount, warningCount});
} else if (this._errorsAndWarnings.has(id)) {
this._errorsAndWarnings.delete(id);
}
Expand All @@ -1097,9 +1086,9 @@ export default class Store extends EventEmitter<{|
let errorCount = 0;
let warningCount = 0;

this._errorsAndWarnings.forEach(({errors, warnings}) => {
errorCount += errors;
warningCount += warnings;
this._errorsAndWarnings.forEach(entry => {
errorCount += entry.errorCount;
warningCount += entry.warningCount;
});

this._cachedErrorCount = errorCount;
Expand Down
12 changes: 6 additions & 6 deletions packages/react-devtools-shared/src/devtools/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ export function printStore(
} else {
const errorsAndWarnings = store._errorsAndWarnings;
if (errorsAndWarnings.size > 0) {
let errorsSum = 0;
let warningsSum = 0;
errorsAndWarnings.forEach(({errors, warnings}) => {
errorsSum += errors;
warningsSum += warnings;
let errorCount = 0;
let warningCount = 0;
errorsAndWarnings.forEach(entry => {
errorCount += entry.errorCount;
warningCount += entry.warningCount;
});

snapshotLines.push(`✕ ${errorsSum}, ⚠ ${warningsSum}`);
snapshotLines.push(`✕ ${errorCount}, ⚠ ${warningCount}`);
}

store.roots.forEach(rootID => {
Expand Down

0 comments on commit 5a3ae6c

Please sign in to comment.