Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DevTools Flow error for key-sort function #17849

Merged
merged 1 commit into from
Jan 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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