Fix DevTools Flow error for key-sort function (#17849)
Brian Vaughn committed
Jan 15, 2020 at 09:45 UTC
bc1f3e1a691be8926b48859fc96ef7ca76590d1e
1 file changed
+11
-2
packages/react-devtools-shared/src/utils.js
+11
-2
@@ -44,7 +44,6 @@ import {
44
ElementTypeMemo,
45
} from 'react-devtools-shared/src/types';
46
import {localStorageGetItem, localStorageSetItem} from './storage';
47
-import {alphaSortEntries} from './devtools/views/utils';
47
import {meta} from './hydration';
48
49
import type {ComponentFilter, ElementType} from './types';
@@ -55,6 +54,16 @@ const cachedDisplayNames: WeakMap<Function, string> = new WeakMap();
54
// Try to reuse the already encoded strings.
55
let encodedStringCache = new LRU({max: 1000});
56
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
+
67
export function getDisplayName(
68
type: Function,
69
fallbackName: string = 'Anonymous',
@@ -601,7 +610,7 @@ export function formatDataForPreview(
610
return data.toString();
611
case 'object':
612
if (showFormattedValue) {
604
- const keys = Object.keys(data).sort(alphaSortEntries);
613
+ const keys = Object.keys(data).sort(alphaSortKeys);
614
615
let formatted = '';
616
for (let i = 0; i < keys.length; i++) {