mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Tidied up a bit
This commit is contained in:
@@ -335,6 +335,7 @@ describe('InspectedElementContext', () => {
|
||||
expect(typed_array[meta.inspectable]).toBe(false);
|
||||
expect(typed_array[meta.name]).toBe('Uint8Array');
|
||||
expect(typed_array[meta.type]).toBe('typed_array');
|
||||
expect(date[meta.inspectable]).toBe(false);
|
||||
expect(date[meta.type]).toBe('date');
|
||||
|
||||
done();
|
||||
|
||||
@@ -124,20 +124,27 @@ describe('InspectedElementContext', () => {
|
||||
typed_array,
|
||||
date,
|
||||
} = inspectedElement.value.props;
|
||||
expect(html_element[meta.inspectable]).toBe(false);
|
||||
expect(html_element[meta.name]).toBe('DIV');
|
||||
expect(html_element[meta.type]).toBe('html_element');
|
||||
expect(fn[meta.inspectable]).toBe(false);
|
||||
expect(fn[meta.name]).toBe('exmapleFunction');
|
||||
expect(fn[meta.type]).toBe('function');
|
||||
expect(symbol[meta.inspectable]).toBe(false);
|
||||
expect(symbol[meta.name]).toBe('Symbol(symbol)');
|
||||
expect(symbol[meta.type]).toBe('symbol');
|
||||
expect(react_element[meta.inspectable]).toBe(false);
|
||||
expect(react_element[meta.name]).toBe('span');
|
||||
expect(react_element[meta.type]).toBe('react_element');
|
||||
expect(array_buffer[meta.size]).toBe(3);
|
||||
expect(array_buffer[meta.inspectable]).toBe(false);
|
||||
expect(array_buffer[meta.name]).toBe('ArrayBuffer');
|
||||
expect(array_buffer[meta.type]).toBe('array_buffer');
|
||||
expect(typed_array[meta.size]).toBe(3);
|
||||
expect(typed_array[meta.inspectable]).toBe(false);
|
||||
expect(typed_array[meta.name]).toBe('Uint8Array');
|
||||
expect(typed_array[meta.type]).toBe('typed_array');
|
||||
expect(date[meta.inspectable]).toBe(false);
|
||||
expect(date[meta.type]).toBe('date');
|
||||
|
||||
done();
|
||||
|
||||
@@ -562,22 +562,20 @@ export function attach(
|
||||
});
|
||||
}
|
||||
|
||||
function isKeyedPathWhitelisted(
|
||||
key: string
|
||||
): (path: Array<string | number>) => boolean {
|
||||
return (path: Array<string | number>) =>
|
||||
isPathWhitelisted([key].concat(path));
|
||||
}
|
||||
|
||||
function isPathWhitelisted(path: Array<string | number>): boolean {
|
||||
let current = currentlyInspectedPaths;
|
||||
for (let i = 0; i < path.length; i++) {
|
||||
current = current[path[i]];
|
||||
function createIsPathWhitelisted(key: string) {
|
||||
return function isPathWhitelisted(path: Array<string | number>): boolean {
|
||||
let current = currentlyInspectedPaths[key];
|
||||
if (!current) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
for (let i = 0; i < path.length; i++) {
|
||||
current = current[path[i]];
|
||||
if (!current) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
function inspectElement(
|
||||
@@ -603,15 +601,15 @@ export function attach(
|
||||
|
||||
inspectedElement.context = cleanForBridge(
|
||||
inspectedElement.context,
|
||||
isKeyedPathWhitelisted('context')
|
||||
createIsPathWhitelisted('context')
|
||||
);
|
||||
inspectedElement.props = cleanForBridge(
|
||||
inspectedElement.props,
|
||||
isKeyedPathWhitelisted('props')
|
||||
createIsPathWhitelisted('props')
|
||||
);
|
||||
inspectedElement.state = cleanForBridge(
|
||||
inspectedElement.state,
|
||||
isKeyedPathWhitelisted('state')
|
||||
createIsPathWhitelisted('state')
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
+21
-20
@@ -2147,26 +2147,27 @@ export function attach(
|
||||
});
|
||||
}
|
||||
|
||||
function isKeyedPathWhitelisted(
|
||||
key: string,
|
||||
isHooks: boolean
|
||||
): (path: Array<string | number>) => boolean {
|
||||
return (path: Array<string | number>) =>
|
||||
isPathWhitelisted([key].concat(path)) ||
|
||||
function createIsPathWhitelisted(isHooksPath: boolean, key: string | null) {
|
||||
return function isPathWhitelisted(path: Array<string | number>): boolean {
|
||||
// Dehydrating the 'subHooks' property makes the HooksTree UI a lot more complicated,
|
||||
// so it's easiest for now if we just don't break on this boundary.
|
||||
(isHooks && path[path.length - 1] === 'subHooks');
|
||||
}
|
||||
if (isHooksPath && path[path.length - 1] === 'subHooks') {
|
||||
return true;
|
||||
}
|
||||
|
||||
function isPathWhitelisted(path: Array<string | number>): boolean {
|
||||
let current = currentlyInspectedPaths;
|
||||
for (let i = 0; i < path.length; i++) {
|
||||
current = current[path[i]];
|
||||
let current =
|
||||
key === null ? currentlyInspectedPaths : currentlyInspectedPaths[key];
|
||||
if (!current) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
for (let i = 0; i < path.length; i++) {
|
||||
current = current[path[i]];
|
||||
if (!current) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
function inspectElement(
|
||||
@@ -2190,7 +2191,7 @@ export function attach(
|
||||
((mostRecentlyInspectedElement: any): InspectedElement),
|
||||
path
|
||||
),
|
||||
isPathWhitelisted,
|
||||
createIsPathWhitelisted(path[0] === 'hooks', null),
|
||||
path
|
||||
),
|
||||
};
|
||||
@@ -2228,23 +2229,23 @@ export function attach(
|
||||
|
||||
cleanedInspectedElement.context = cleanForBridge(
|
||||
cleanedInspectedElement.context,
|
||||
isKeyedPathWhitelisted('context', false)
|
||||
createIsPathWhitelisted(false, 'context')
|
||||
);
|
||||
cleanedInspectedElement.events = cleanForBridge(
|
||||
cleanedInspectedElement.events,
|
||||
isKeyedPathWhitelisted('events', false)
|
||||
createIsPathWhitelisted(false, 'events')
|
||||
);
|
||||
cleanedInspectedElement.hooks = cleanForBridge(
|
||||
cleanedInspectedElement.hooks,
|
||||
isKeyedPathWhitelisted('hooks', true)
|
||||
createIsPathWhitelisted(true, 'hooks')
|
||||
);
|
||||
cleanedInspectedElement.props = cleanForBridge(
|
||||
cleanedInspectedElement.props,
|
||||
isKeyedPathWhitelisted('props', false)
|
||||
createIsPathWhitelisted(false, 'props')
|
||||
);
|
||||
cleanedInspectedElement.state = cleanForBridge(
|
||||
cleanedInspectedElement.state,
|
||||
isKeyedPathWhitelisted('state', false)
|
||||
createIsPathWhitelisted(false, 'state')
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user