Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/react-devtools-shared/src/isArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

const isArray = Array.isArray;

export default isArray;
9 changes: 5 additions & 4 deletions packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
} from 'react-devtools-shared/src/types';
import {localStorageGetItem, localStorageSetItem} from './storage';
import {meta} from './hydration';
import isArray from './isArray';

import type {ComponentFilter, ElementType} from './types';
import type {LRUCache} from 'react-devtools-shared/src/types';
Expand Down Expand Up @@ -455,7 +456,7 @@ export function deletePathInObject(
if (object != null) {
const parent = getInObject(object, path.slice(0, length - 1));
if (parent) {
if (Array.isArray(parent)) {
if (isArray(parent)) {
parent.splice(((last: any): number), 1);
} else {
delete parent[last];
Expand All @@ -476,7 +477,7 @@ export function renamePathInObject(
const lastOld = oldPath[length - 1];
const lastNew = newPath[length - 1];
parent[lastNew] = parent[lastOld];
if (Array.isArray(parent)) {
if (isArray(parent)) {
parent.splice(((lastOld: any): number), 1);
} else {
delete parent[lastOld];
Expand Down Expand Up @@ -560,7 +561,7 @@ export function getDataType(data: Object): DataType {
return 'number';
}
case 'object':
if (Array.isArray(data)) {
if (isArray(data)) {
return 'array';
} else if (ArrayBuffer.isView(data)) {
return hasOwnProperty.call(data.constructor, 'BYTES_PER_ELEMENT')
Expand Down Expand Up @@ -779,7 +780,7 @@ export function formatDataForPreview(
// To mimic their behavior, detect if we've been given an entries tuple.
// Map(2) {"abc" => 123, "def" => 123}
// Set(2) {"abc", 123}
if (Array.isArray(entryOrEntries)) {
if (isArray(entryOrEntries)) {
const key = formatDataForPreview(entryOrEntries[0], true);
const value = formatDataForPreview(entryOrEntries[1], false);
formatted += `${key} => ${value}`;
Expand Down