From 3df84791f15b94ff8c815db3753cdaf60dccff48 Mon Sep 17 00:00:00 2001 From: Behnam Mohammadi Date: Fri, 21 Jan 2022 18:03:00 +0330 Subject: [PATCH] styles: replace Array.isArray with module isArray (#23154) --- .../backend/NativeStyleEditor/setupNativeStyleEditor.js | 9 +++++---- .../react-devtools-shared/src/backend/StyleX/utils.js | 5 +++-- .../views/Components/InspectedElementHooksTree.js | 5 +++-- .../src/devtools/views/Components/KeyValue.js | 3 ++- .../react-devtools-shared/src/devtools/views/utils.js | 3 ++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js b/packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js index 221ad7a9c4800..561068bbb1224 100644 --- a/packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js +++ b/packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js @@ -9,6 +9,7 @@ import Agent from 'react-devtools-shared/src/backend/agent'; import resolveBoxStyle from './resolveBoxStyle'; +import isArray from 'react-devtools-shared/src/isArray'; import type {BackendBridge} from 'react-devtools-shared/src/bridge'; import type {RendererID} from '../types'; @@ -210,11 +211,11 @@ function renameStyle( } // TODO Fabric does not support setNativeProps; chat with Sebastian or Eli instance.setNativeProps({style: newStyle}); - } else if (Array.isArray(style)) { + } else if (isArray(style)) { const lastIndex = style.length - 1; if ( typeof style[lastIndex] === 'object' && - !Array.isArray(style[lastIndex]) + !isArray(style[lastIndex]) ) { customStyle = shallowClone(style[lastIndex]); delete customStyle[oldName]; @@ -296,11 +297,11 @@ function setStyle( } // TODO Fabric does not support setNativeProps; chat with Sebastian or Eli instance.setNativeProps({style: newStyle}); - } else if (Array.isArray(style)) { + } else if (isArray(style)) { const lastLength = style.length - 1; if ( typeof style[lastLength] === 'object' && - !Array.isArray(style[lastLength]) + !isArray(style[lastLength]) ) { agent.overrideValueAtPath({ type: 'props', diff --git a/packages/react-devtools-shared/src/backend/StyleX/utils.js b/packages/react-devtools-shared/src/backend/StyleX/utils.js index 6bf5a2978927e..14035204a8ddf 100644 --- a/packages/react-devtools-shared/src/backend/StyleX/utils.js +++ b/packages/react-devtools-shared/src/backend/StyleX/utils.js @@ -8,6 +8,7 @@ */ import type {StyleXPlugin} from 'react-devtools-shared/src/types'; +import isArray from 'react-devtools-shared/src/isArray'; const cachedStyleNameToValueMap: Map = new Map(); @@ -28,9 +29,9 @@ export function crawlData( sources: Set, resolvedStyles: Object, ): void { - if (Array.isArray(data)) { + if (isArray(data)) { data.forEach(entry => { - if (Array.isArray(entry)) { + if (isArray(entry)) { crawlData(entry, sources, resolvedStyles); } else { crawlObjectProperties(entry, sources, resolvedStyles); diff --git a/packages/react-devtools-shared/src/devtools/views/Components/InspectedElementHooksTree.js b/packages/react-devtools-shared/src/devtools/views/Components/InspectedElementHooksTree.js index 83450dc616bb9..f00d9dd0eb504 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/InspectedElementHooksTree.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/InspectedElementHooksTree.js @@ -27,6 +27,7 @@ import { enableProfilerChangedHookIndices, } from 'react-devtools-feature-flags'; import HookNamesModuleLoaderContext from 'react-devtools-shared/src/devtools/views/Components/HookNamesModuleLoaderContext'; +import isArray from 'react-devtools-shared/src/isArray'; import type {InspectedElement} from './types'; import type {HooksNode, HooksTree} from 'react-debug-tools/src/ReactDebugHooks'; @@ -269,7 +270,7 @@ function HookView({ displayValue = 'null'; } else if (value === undefined) { displayValue = null; - } else if (Array.isArray(value)) { + } else if (isArray(value)) { isComplexDisplayValue = true; displayValue = 'Array'; } else if (type === 'object') { @@ -278,7 +279,7 @@ function HookView({ } if (isCustomHook) { - const subHooksView = Array.isArray(subHooks) ? ( + const subHooksView = isArray(subHooks) ? ( 0 || canEditValues; const displayName = getMetaValueLabel(value); diff --git a/packages/react-devtools-shared/src/devtools/views/utils.js b/packages/react-devtools-shared/src/devtools/views/utils.js index 035d9f83a3bc5..ae9c4ddff309c 100644 --- a/packages/react-devtools-shared/src/devtools/views/utils.js +++ b/packages/react-devtools-shared/src/devtools/views/utils.js @@ -10,6 +10,7 @@ import escapeStringRegExp from 'escape-string-regexp'; import {meta} from '../../hydration'; import {formatDataForPreview} from '../../utils'; +import isArray from 'react-devtools-shared/src/isArray'; import type {HooksTree} from 'react-debug-tools/src/ReactDebugHooks'; @@ -107,7 +108,7 @@ function sanitize(data: Object): void { if (value && value[meta.type]) { data[key] = getMetaValueLabel(value); } else if (value != null) { - if (Array.isArray(value)) { + if (isArray(value)) { sanitize(value); } else if (typeof value === 'object') { sanitize(value);