Skip to content

Commit 3df8479

Browse files
behnammodinevilm-lt
authored andcommitted
styles: replace Array.isArray with module isArray (facebook#23154)
1 parent d9ddcee commit 3df8479

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import Agent from 'react-devtools-shared/src/backend/agent';
1111
import resolveBoxStyle from './resolveBoxStyle';
12+
import isArray from 'react-devtools-shared/src/isArray';
1213

1314
import type {BackendBridge} from 'react-devtools-shared/src/bridge';
1415
import type {RendererID} from '../types';
@@ -210,11 +211,11 @@ function renameStyle(
210211
}
211212
// TODO Fabric does not support setNativeProps; chat with Sebastian or Eli
212213
instance.setNativeProps({style: newStyle});
213-
} else if (Array.isArray(style)) {
214+
} else if (isArray(style)) {
214215
const lastIndex = style.length - 1;
215216
if (
216217
typeof style[lastIndex] === 'object' &&
217-
!Array.isArray(style[lastIndex])
218+
!isArray(style[lastIndex])
218219
) {
219220
customStyle = shallowClone(style[lastIndex]);
220221
delete customStyle[oldName];
@@ -296,11 +297,11 @@ function setStyle(
296297
}
297298
// TODO Fabric does not support setNativeProps; chat with Sebastian or Eli
298299
instance.setNativeProps({style: newStyle});
299-
} else if (Array.isArray(style)) {
300+
} else if (isArray(style)) {
300301
const lastLength = style.length - 1;
301302
if (
302303
typeof style[lastLength] === 'object' &&
303-
!Array.isArray(style[lastLength])
304+
!isArray(style[lastLength])
304305
) {
305306
agent.overrideValueAtPath({
306307
type: 'props',

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import type {StyleXPlugin} from 'react-devtools-shared/src/types';
11+
import isArray from 'react-devtools-shared/src/isArray';
1112

1213
const cachedStyleNameToValueMap: Map<string, string> = new Map();
1314

@@ -28,9 +29,9 @@ export function crawlData(
2829
sources: Set<string>,
2930
resolvedStyles: Object,
3031
): void {
31-
if (Array.isArray(data)) {
32+
if (isArray(data)) {
3233
data.forEach(entry => {
33-
if (Array.isArray(entry)) {
34+
if (isArray(entry)) {
3435
crawlData(entry, sources, resolvedStyles);
3536
} else {
3637
crawlObjectProperties(entry, sources, resolvedStyles);

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementHooksTree.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
enableProfilerChangedHookIndices,
2828
} from 'react-devtools-feature-flags';
2929
import HookNamesModuleLoaderContext from 'react-devtools-shared/src/devtools/views/Components/HookNamesModuleLoaderContext';
30+
import isArray from 'react-devtools-shared/src/isArray';
3031

3132
import type {InspectedElement} from './types';
3233
import type {HooksNode, HooksTree} from 'react-debug-tools/src/ReactDebugHooks';
@@ -269,7 +270,7 @@ function HookView({
269270
displayValue = 'null';
270271
} else if (value === undefined) {
271272
displayValue = null;
272-
} else if (Array.isArray(value)) {
273+
} else if (isArray(value)) {
273274
isComplexDisplayValue = true;
274275
displayValue = 'Array';
275276
} else if (type === 'object') {
@@ -278,7 +279,7 @@ function HookView({
278279
}
279280

280281
if (isCustomHook) {
281-
const subHooksView = Array.isArray(subHooks) ? (
282+
const subHooksView = isArray(subHooks) ? (
282283
<InnerHooksTreeView
283284
element={element}
284285
hooks={subHooks}

packages/react-devtools-shared/src/devtools/views/Components/KeyValue.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {parseHookPathForEdit} from './utils';
2424
import styles from './KeyValue.css';
2525
import Button from 'react-devtools-shared/src/devtools/views/Button';
2626
import ButtonIcon from 'react-devtools-shared/src/devtools/views/ButtonIcon';
27+
import isArray from 'react-devtools-shared/src/isArray';
2728
import {InspectedElementContext} from './InspectedElementContext';
2829
import {PROTOCOLS_SUPPORTED_AS_LINKS_IN_KEY_VALUE} from './constants';
2930

@@ -327,7 +328,7 @@ export default function KeyValue({
327328
);
328329
}
329330
} else {
330-
if (Array.isArray(value)) {
331+
if (isArray(value)) {
331332
const hasChildren = value.length > 0 || canEditValues;
332333
const displayName = getMetaValueLabel(value);
333334

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import escapeStringRegExp from 'escape-string-regexp';
1111
import {meta} from '../../hydration';
1212
import {formatDataForPreview} from '../../utils';
13+
import isArray from 'react-devtools-shared/src/isArray';
1314

1415
import type {HooksTree} from 'react-debug-tools/src/ReactDebugHooks';
1516

@@ -107,7 +108,7 @@ function sanitize(data: Object): void {
107108
if (value && value[meta.type]) {
108109
data[key] = getMetaValueLabel(value);
109110
} else if (value != null) {
110-
if (Array.isArray(value)) {
111+
if (isArray(value)) {
111112
sanitize(value);
112113
} else if (typeof value === 'object') {
113114
sanitize(value);

0 commit comments

Comments
 (0)