Skip to content

Commit

Permalink
Fix DevTools Flow error for key-sort function (#17849)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn authored Jan 15, 2020
1 parent b6173e6 commit bc1f3e1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit bc1f3e1

Please sign in to comment.