@samitouri / QOS-React / commits / 26baf6a174

styles: replace Array.isArray with module isArray (#23154)

Behnam Mohammadi committed Jan 21, 2022 at 18:03 UTC 26baf6a174d97bf4821c54e0083e69422cb87f45
5 files changed +15 -10
packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js
+5 -4
@@ -9,6 +9,7 @@
9
10 import Agent from 'react-devtools-shared/src/backend/agent';
11 import resolveBoxStyle from './resolveBoxStyle';
12 +import isArray from 'react-devtools-shared/src/isArray';
13
14 import type {BackendBridge} from 'react-devtools-shared/src/bridge';
15 import type {RendererID} from '../types';
@@ -210,11 +211,11 @@ function renameStyle(
211 }
212 // TODO Fabric does not support setNativeProps; chat with Sebastian or Eli
213 instance.setNativeProps({style: newStyle});
213 - } else if (Array.isArray(style)) {
214 + } else if (isArray(style)) {
215 const lastIndex = style.length - 1;
216 if (
217 typeof style[lastIndex] === 'object' &&
217 - !Array.isArray(style[lastIndex])
218 + !isArray(style[lastIndex])
219 ) {
220 customStyle = shallowClone(style[lastIndex]);
221 delete customStyle[oldName];
@@ -296,11 +297,11 @@ function setStyle(
297 }
298 // TODO Fabric does not support setNativeProps; chat with Sebastian or Eli
299 instance.setNativeProps({style: newStyle});
299 - } else if (Array.isArray(style)) {
300 + } else if (isArray(style)) {
301 const lastLength = style.length - 1;
302 if (
303 typeof style[lastLength] === 'object' &&
303 - !Array.isArray(style[lastLength])
304 + !isArray(style[lastLength])
305 ) {
306 agent.overrideValueAtPath({
307 type: 'props',
packages/react-devtools-shared/src/backend/StyleX/utils.js
+3 -2
@@ -8,6 +8,7 @@
8 */
9
10 import type {StyleXPlugin} from 'react-devtools-shared/src/types';
11 +import isArray from 'react-devtools-shared/src/isArray';
12
13 const cachedStyleNameToValueMap: Map<string, string> = new Map();
14
@@ -28,9 +29,9 @@ export function crawlData(
29 sources: Set<string>,
30 resolvedStyles: Object,
31 ): void {
31 - if (Array.isArray(data)) {
32 + if (isArray(data)) {
33 data.forEach(entry => {
33 - if (Array.isArray(entry)) {
34 + if (isArray(entry)) {
35 crawlData(entry, sources, resolvedStyles);
36 } else {
37 crawlObjectProperties(entry, sources, resolvedStyles);
packages/react-devtools-shared/src/devtools/views/Components/InspectedElementHooksTree.js
+3 -2
@@ -27,6 +27,7 @@ import {
27 enableProfilerChangedHookIndices,
28 } from 'react-devtools-feature-flags';
29 import HookNamesModuleLoaderContext from 'react-devtools-shared/src/devtools/views/Components/HookNamesModuleLoaderContext';
30 +import isArray from 'react-devtools-shared/src/isArray';
31
32 import type {InspectedElement} from './types';
33 import type {HooksNode, HooksTree} from 'react-debug-tools/src/ReactDebugHooks';
@@ -269,7 +270,7 @@ function HookView({
270 displayValue = 'null';
271 } else if (value === undefined) {
272 displayValue = null;
272 - } else if (Array.isArray(value)) {
273 + } else if (isArray(value)) {
274 isComplexDisplayValue = true;
275 displayValue = 'Array';
276 } else if (type === 'object') {
@@ -278,7 +279,7 @@ function HookView({
279 }
280
281 if (isCustomHook) {
281 - const subHooksView = Array.isArray(subHooks) ? (
282 + const subHooksView = isArray(subHooks) ? (
283 <InnerHooksTreeView
284 element={element}
285 hooks={subHooks}
packages/react-devtools-shared/src/devtools/views/Components/KeyValue.js
+2 -1
@@ -24,6 +24,7 @@ import {parseHookPathForEdit} from './utils';
24 import styles from './KeyValue.css';
25 import Button from 'react-devtools-shared/src/devtools/views/Button';
26 import ButtonIcon from 'react-devtools-shared/src/devtools/views/ButtonIcon';
27 +import isArray from 'react-devtools-shared/src/isArray';
28 import {InspectedElementContext} from './InspectedElementContext';
29 import {PROTOCOLS_SUPPORTED_AS_LINKS_IN_KEY_VALUE} from './constants';
30
@@ -327,7 +328,7 @@ export default function KeyValue({
328 );
329 }
330 } else {
330 - if (Array.isArray(value)) {
331 + if (isArray(value)) {
332 const hasChildren = value.length > 0 || canEditValues;
333 const displayName = getMetaValueLabel(value);
334
packages/react-devtools-shared/src/devtools/views/utils.js
+2 -1
@@ -10,6 +10,7 @@
10 import escapeStringRegExp from 'escape-string-regexp';
11 import {meta} from '../../hydration';
12 import {formatDataForPreview} from '../../utils';
13 +import isArray from 'react-devtools-shared/src/isArray';
14
15 import type {HooksTree} from 'react-debug-tools/src/ReactDebugHooks';
16
@@ -107,7 +108,7 @@ function sanitize(data: Object): void {
108 if (value && value[meta.type]) {
109 data[key] = getMetaValueLabel(value);
110 } else if (value != null) {
110 - if (Array.isArray(value)) {
111 + if (isArray(value)) {
112 sanitize(value);
113 } else if (typeof value === 'object') {
114 sanitize(value);