Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

styles: replace Array.isArray with module isArray #23154

Merged
merged 1 commit into from
Jan 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions packages/react-devtools-shared/src/backend/StyleX/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

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

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

Expand All @@ -28,9 +29,9 @@ export function crawlData(
sources: Set<string>,
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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') {
Expand All @@ -278,7 +279,7 @@ function HookView({
}

if (isCustomHook) {
const subHooksView = Array.isArray(subHooks) ? (
const subHooksView = isArray(subHooks) ? (
<InnerHooksTreeView
element={element}
hooks={subHooks}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {parseHookPathForEdit} from './utils';
import styles from './KeyValue.css';
import Button from 'react-devtools-shared/src/devtools/views/Button';
import ButtonIcon from 'react-devtools-shared/src/devtools/views/ButtonIcon';
import isArray from 'react-devtools-shared/src/isArray';
import {InspectedElementContext} from './InspectedElementContext';
import {PROTOCOLS_SUPPORTED_AS_LINKS_IN_KEY_VALUE} from './constants';

Expand Down Expand Up @@ -327,7 +328,7 @@ export default function KeyValue({
);
}
} else {
if (Array.isArray(value)) {
if (isArray(value)) {
const hasChildren = value.length > 0 || canEditValues;
const displayName = getMetaValueLabel(value);

Expand Down
3 changes: 2 additions & 1 deletion packages/react-devtools-shared/src/devtools/views/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down