Skip to content

Commit bc1f3e1

Browse files
author
Brian Vaughn
authored
Fix DevTools Flow error for key-sort function (#17849)
1 parent b6173e6 commit bc1f3e1

File tree

1 file changed

+11
-2
lines changed
  • packages/react-devtools-shared/src

1 file changed

+11
-2
lines changed

packages/react-devtools-shared/src/utils.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import {
4444
ElementTypeMemo,
4545
} from 'react-devtools-shared/src/types';
4646
import {localStorageGetItem, localStorageSetItem} from './storage';
47-
import {alphaSortEntries} from './devtools/views/utils';
4847
import {meta} from './hydration';
4948

5049
import type {ComponentFilter, ElementType} from './types';
@@ -55,6 +54,16 @@ const cachedDisplayNames: WeakMap<Function, string> = new WeakMap();
5554
// Try to reuse the already encoded strings.
5655
let encodedStringCache = new LRU({max: 1000});
5756

57+
export function alphaSortKeys(a: string, b: string): number {
58+
if (a > b) {
59+
return 1;
60+
} else if (b > a) {
61+
return -1;
62+
} else {
63+
return 0;
64+
}
65+
}
66+
5867
export function getDisplayName(
5968
type: Function,
6069
fallbackName: string = 'Anonymous',
@@ -601,7 +610,7 @@ export function formatDataForPreview(
601610
return data.toString();
602611
case 'object':
603612
if (showFormattedValue) {
604-
const keys = Object.keys(data).sort(alphaSortEntries);
613+
const keys = Object.keys(data).sort(alphaSortKeys);
605614

606615
let formatted = '';
607616
for (let i = 0; i < keys.length; i++) {

0 commit comments

Comments
 (0)