Skip to content

Commit 580e2f5

Browse files
authored
Add isArray in devTools utils (#22438)
1 parent d3e0869 commit 580e2f5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
const isArray = Array.isArray;
11+
12+
export default isArray;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
} from 'react-devtools-shared/src/types';
4949
import {localStorageGetItem, localStorageSetItem} from './storage';
5050
import {meta} from './hydration';
51+
import isArray from './isArray';
5152

5253
import type {ComponentFilter, ElementType} from './types';
5354
import type {LRUCache} from 'react-devtools-shared/src/types';
@@ -475,7 +476,7 @@ export function deletePathInObject(
475476
if (object != null) {
476477
const parent = getInObject(object, path.slice(0, length - 1));
477478
if (parent) {
478-
if (Array.isArray(parent)) {
479+
if (isArray(parent)) {
479480
parent.splice(((last: any): number), 1);
480481
} else {
481482
delete parent[last];
@@ -496,7 +497,7 @@ export function renamePathInObject(
496497
const lastOld = oldPath[length - 1];
497498
const lastNew = newPath[length - 1];
498499
parent[lastNew] = parent[lastOld];
499-
if (Array.isArray(parent)) {
500+
if (isArray(parent)) {
500501
parent.splice(((lastOld: any): number), 1);
501502
} else {
502503
delete parent[lastOld];
@@ -580,7 +581,7 @@ export function getDataType(data: Object): DataType {
580581
return 'number';
581582
}
582583
case 'object':
583-
if (Array.isArray(data)) {
584+
if (isArray(data)) {
584585
return 'array';
585586
} else if (ArrayBuffer.isView(data)) {
586587
return hasOwnProperty.call(data.constructor, 'BYTES_PER_ELEMENT')
@@ -799,7 +800,7 @@ export function formatDataForPreview(
799800
// To mimic their behavior, detect if we've been given an entries tuple.
800801
// Map(2) {"abc" => 123, "def" => 123}
801802
// Set(2) {"abc", 123}
802-
if (Array.isArray(entryOrEntries)) {
803+
if (isArray(entryOrEntries)) {
803804
const key = formatDataForPreview(entryOrEntries[0], true);
804805
const value = formatDataForPreview(entryOrEntries[1], false);
805806
formatted += `${key} => ${value}`;

0 commit comments

Comments
 (0)