mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix DevTools Flow error for key-sort function (#17849)
This commit is contained in:
+11
-2
@@ -44,7 +44,6 @@ import {
|
||||
ElementTypeMemo,
|
||||
} from 'react-devtools-shared/src/types';
|
||||
import {localStorageGetItem, localStorageSetItem} from './storage';
|
||||
import {alphaSortEntries} from './devtools/views/utils';
|
||||
import {meta} from './hydration';
|
||||
|
||||
import type {ComponentFilter, ElementType} from './types';
|
||||
@@ -55,6 +54,16 @@ const cachedDisplayNames: WeakMap<Function, string> = new WeakMap();
|
||||
// Try to reuse the already encoded strings.
|
||||
let encodedStringCache = new LRU({max: 1000});
|
||||
|
||||
export function alphaSortKeys(a: string, b: string): number {
|
||||
if (a > b) {
|
||||
return 1;
|
||||
} else if (b > a) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export function getDisplayName(
|
||||
type: Function,
|
||||
fallbackName: string = 'Anonymous',
|
||||
@@ -601,7 +610,7 @@ export function formatDataForPreview(
|
||||
return data.toString();
|
||||
case 'object':
|
||||
if (showFormattedValue) {
|
||||
const keys = Object.keys(data).sort(alphaSortEntries);
|
||||
const keys = Object.keys(data).sort(alphaSortKeys);
|
||||
|
||||
let formatted = '';
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user