Misc cleanup

This commit is contained in:
Brian Vaughn
2019-05-01 14:18:20 -07:00
parent e6da4b9058
commit 4a4786ac2f
5 changed files with 24 additions and 30 deletions
@@ -61,6 +61,13 @@ describe('Store component filters', () => {
Types = require('src/types');
});
it('should throw if filters are updated while profiling', () => {
act(() => store.startProfiling());
expect(() => (store.componentFilters = [])).toThrow(
'Cannot modify filter preferences while profiling'
);
});
it('should support filtering by element type', () => {
class Root extends React.Component<{| children: React$Node |}> {
render() {
+16 -14
View File
@@ -306,7 +306,7 @@ export function attach(
applyComponentFilters(getSavedComponentFilters());
// TODO (filter) Should we make this operation more efficient?
// If necessary, we can revisit optimizing this operation.
// For example, we could add a new recursive unmount tree operation.
// The unmount operations are already significantly smaller than mount opreations though.
// This is something to keep in mind for later.
@@ -317,7 +317,7 @@ export function attach(
throw Error('Cannot modify filter preferences while profiling');
}
// Recursively unmount and then re-mount all roots.
// Recursively unmount all roots.
hook.getFiberRoots(rendererID).forEach(root => {
currentRootID = getFiberID(getPrimaryFiber(root.current));
unmountFiberChildrenRecursively(root.current);
@@ -372,16 +372,18 @@ export function attach(
}
}
const elementType = getTypeForFiber(fiber);
const elementType = getElementTypeForFiber(fiber);
if (hideElementsWithTypes.has(elementType)) {
return true;
}
if (hideElementsWithDisplayNames.size > 0) {
const displayName = getDisplayNameForFiber(fiber) || '';
for (let displayNameRegExp of hideElementsWithDisplayNames) {
if (displayNameRegExp.test(displayName)) {
return true;
const displayName = getDisplayNameForFiber(fiber);
if (displayName != null) {
for (let displayNameRegExp of hideElementsWithDisplayNames) {
if (displayNameRegExp.test(displayName)) {
return true;
}
}
}
}
@@ -473,14 +475,14 @@ export function attach(
case CONTEXT_PROVIDER_SYMBOL_STRING:
// 16.3.0 exposed the context object as "context"
// PR #12501 changed it to "_context" for 16.3.1+
// NOTE Keep in sync with inspectElement()
// NOTE Keep in sync with inspectElementRaw()
resolvedContext = fiber.type._context || fiber.type.context;
return `${resolvedContext.displayName || 'Context'}.Provider`;
case CONTEXT_CONSUMER_NUMBER:
case CONTEXT_CONSUMER_SYMBOL_STRING:
// 16.3-16.5 read from "type" because the Consumer is the actual context object.
// 16.6+ should read from "type._context" because Consumer can be different (in DEV).
// NOTE Keep in sync with inspectElement()
// NOTE Keep in sync with inspectElementRaw()
resolvedContext = fiber.type._context || fiber.type;
// NOTE: TraceUpdatesBackendManager depends on the name ending in '.Consumer'
@@ -505,7 +507,7 @@ export function attach(
}
// NOTICE Keep in sync with shouldFilterFiber() and other get*ForFiber methods
function getTypeForFiber(fiber: Fiber): ElementType {
function getElementTypeForFiber(fiber: Fiber): ElementType {
const { type, tag } = fiber;
switch (tag) {
@@ -785,7 +787,7 @@ export function attach(
} else {
const { key } = fiber;
const displayName = getDisplayNameForFiber(fiber);
const type = getTypeForFiber(fiber);
const elementType = getElementTypeForFiber(fiber);
const { _debugOwner } = fiber;
const ownerID =
@@ -796,7 +798,7 @@ export function attach(
let keyStringID = getStringID(key);
pushOperation(TREE_OPERATION_ADD);
pushOperation(id);
pushOperation(type);
pushOperation(elementType);
pushOperation(parentID);
pushOperation(ownerID);
pushOperation(displayNameStringID);
@@ -1645,7 +1647,7 @@ export function attach(
) {
// 16.3-16.5 read from "type" because the Consumer is the actual context object.
// 16.6+ should read from "type._context" because Consumer can be different (in DEV).
// NOTE Keep in sync with get*ForFiber methods
// NOTE Keep in sync with getDisplayNameForFiber()
const consumerResolvedContext = type._context || type;
// Global context value.
@@ -1662,7 +1664,7 @@ export function attach(
) {
// 16.3.0 exposed the context object as "context"
// PR #12501 changed it to "_context" for 16.3.1+
// NOTE Keep in sync with get*ForFiber methods
// NOTE Keep in sync with getDisplayNameForFiber()
const providerResolvedContext =
currentType._context || currentType.context;
if (providerResolvedContext === consumerResolvedContext) {
-14
View File
@@ -25,8 +25,6 @@ export type IconType =
| 'save'
| 'search'
| 'settings'
| 'toggle_off'
| 'toggle_on'
| 'undo'
| 'up'
| 'view-dom'
@@ -103,12 +101,6 @@ export default function ButtonIcon({ className = '', type }: Props) {
case 'settings':
pathData = PATH_SETTINGS;
break;
case 'toggle_off':
pathData = PATH_TOGGLE_OFF;
break;
case 'toggle_on':
pathData = PATH_TOGGLE_ON;
break;
case 'undo':
pathData = PATH_UNDO;
break;
@@ -220,12 +212,6 @@ const PATH_SETTINGS = `
.49-.18l1.6-2.77c.1-.18.06-.39-.1-.51l-1.67-1.32zM10 13c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z
`;
const PATH_TOGGLE_OFF =
'M17 7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h10c2.76 0 5-2.24 5-5s-2.24-5-5-5zM7 15c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3z';
const PATH_TOGGLE_ON =
'M17 7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h10c2.76 0 5-2.24 5-5s-2.24-5-5-5zm0 8c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3z';
const PATH_UNDO = `
M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88
3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z
@@ -251,7 +251,6 @@ function updateThemeVariables(
updateStyleHelper(theme, 'color-toggle-background-on', documentElements);
updateStyleHelper(theme, 'color-toggle-background-off', documentElements);
updateStyleHelper(theme, 'color-toggle-text', documentElements);
updateStyleHelper(theme, 'color-toggle-text', documentElements);
updateStyleHelper(theme, 'color-tooltip-background', documentElements);
updateStyleHelper(theme, 'color-tooltip-text', documentElements);
+1 -1
View File
@@ -50,7 +50,7 @@ export function useLocalStorage<T>(
console.log(error);
}
if (typeof initialValue === 'function') {
return (initialValue: any)();
return ((initialValue: any): () => T)();
} else {
return initialValue;
}