@samitouri / QOS-React / commits / 4a4786ac2f

Misc cleanup

Brian Vaughn committed May 1, 2019 at 14:18 UTC 4a4786ac2faaa558a4bb32a51cf6eaedcefb2cdc
5 files changed +24 -30
src/__tests__/storeComponentFilters-test.js
+7
@@ -61,6 +61,13 @@ describe('Store component filters', () => {
61 Types = require('src/types');
62 });
63
64 + it('should throw if filters are updated while profiling', () => {
65 + act(() => store.startProfiling());
66 + expect(() => (store.componentFilters = [])).toThrow(
67 + 'Cannot modify filter preferences while profiling'
68 + );
69 + });
70 +
71 it('should support filtering by element type', () => {
72 class Root extends React.Component<{| children: React$Node |}> {
73 render() {
src/backend/renderer.js
+16 -14
@@ -306,7 +306,7 @@ export function attach(
306
307 applyComponentFilters(getSavedComponentFilters());
308
309 - // TODO (filter) Should we make this operation more efficient?
309 + // If necessary, we can revisit optimizing this operation.
310 // For example, we could add a new recursive unmount tree operation.
311 // The unmount operations are already significantly smaller than mount opreations though.
312 // This is something to keep in mind for later.
@@ -317,7 +317,7 @@ export function attach(
317 throw Error('Cannot modify filter preferences while profiling');
318 }
319
320 - // Recursively unmount and then re-mount all roots.
320 + // Recursively unmount all roots.
321 hook.getFiberRoots(rendererID).forEach(root => {
322 currentRootID = getFiberID(getPrimaryFiber(root.current));
323 unmountFiberChildrenRecursively(root.current);
@@ -372,16 +372,18 @@ export function attach(
372 }
373 }
374
375 - const elementType = getTypeForFiber(fiber);
375 + const elementType = getElementTypeForFiber(fiber);
376 if (hideElementsWithTypes.has(elementType)) {
377 return true;
378 }
379
380 if (hideElementsWithDisplayNames.size > 0) {
381 - const displayName = getDisplayNameForFiber(fiber) || '';
382 - for (let displayNameRegExp of hideElementsWithDisplayNames) {
383 - if (displayNameRegExp.test(displayName)) {
384 - return true;
381 + const displayName = getDisplayNameForFiber(fiber);
382 + if (displayName != null) {
383 + for (let displayNameRegExp of hideElementsWithDisplayNames) {
384 + if (displayNameRegExp.test(displayName)) {
385 + return true;
386 + }
387 }
388 }
389 }
@@ -473,14 +475,14 @@ export function attach(
475 case CONTEXT_PROVIDER_SYMBOL_STRING:
476 // 16.3.0 exposed the context object as "context"
477 // PR #12501 changed it to "_context" for 16.3.1+
476 - // NOTE Keep in sync with inspectElement()
478 + // NOTE Keep in sync with inspectElementRaw()
479 resolvedContext = fiber.type._context || fiber.type.context;
480 return `${resolvedContext.displayName || 'Context'}.Provider`;
481 case CONTEXT_CONSUMER_NUMBER:
482 case CONTEXT_CONSUMER_SYMBOL_STRING:
483 // 16.3-16.5 read from "type" because the Consumer is the actual context object.
484 // 16.6+ should read from "type._context" because Consumer can be different (in DEV).
483 - // NOTE Keep in sync with inspectElement()
485 + // NOTE Keep in sync with inspectElementRaw()
486 resolvedContext = fiber.type._context || fiber.type;
487
488 // NOTE: TraceUpdatesBackendManager depends on the name ending in '.Consumer'
@@ -505,7 +507,7 @@ export function attach(
507 }
508
509 // NOTICE Keep in sync with shouldFilterFiber() and other get*ForFiber methods
508 - function getTypeForFiber(fiber: Fiber): ElementType {
510 + function getElementTypeForFiber(fiber: Fiber): ElementType {
511 const { type, tag } = fiber;
512
513 switch (tag) {
@@ -785,7 +787,7 @@ export function attach(
787 } else {
788 const { key } = fiber;
789 const displayName = getDisplayNameForFiber(fiber);
788 - const type = getTypeForFiber(fiber);
790 + const elementType = getElementTypeForFiber(fiber);
791 const { _debugOwner } = fiber;
792
793 const ownerID =
@@ -796,7 +798,7 @@ export function attach(
798 let keyStringID = getStringID(key);
799 pushOperation(TREE_OPERATION_ADD);
800 pushOperation(id);
799 - pushOperation(type);
801 + pushOperation(elementType);
802 pushOperation(parentID);
803 pushOperation(ownerID);
804 pushOperation(displayNameStringID);
@@ -1645,7 +1647,7 @@ export function attach(
1647 ) {
1648 // 16.3-16.5 read from "type" because the Consumer is the actual context object.
1649 // 16.6+ should read from "type._context" because Consumer can be different (in DEV).
1648 - // NOTE Keep in sync with get*ForFiber methods
1650 + // NOTE Keep in sync with getDisplayNameForFiber()
1651 const consumerResolvedContext = type._context || type;
1652
1653 // Global context value.
@@ -1662,7 +1664,7 @@ export function attach(
1664 ) {
1665 // 16.3.0 exposed the context object as "context"
1666 // PR #12501 changed it to "_context" for 16.3.1+
1665 - // NOTE Keep in sync with get*ForFiber methods
1667 + // NOTE Keep in sync with getDisplayNameForFiber()
1668 const providerResolvedContext =
1669 currentType._context || currentType.context;
1670 if (providerResolvedContext === consumerResolvedContext) {
src/devtools/views/ButtonIcon.js
-14
@@ -25,8 +25,6 @@ export type IconType =
25 | 'save'
26 | 'search'
27 | 'settings'
28 - | 'toggle_off'
29 - | 'toggle_on'
28 | 'undo'
29 | 'up'
30 | 'view-dom'
@@ -103,12 +101,6 @@ export default function ButtonIcon({ className = '', type }: Props) {
101 case 'settings':
102 pathData = PATH_SETTINGS;
103 break;
106 - case 'toggle_off':
107 - pathData = PATH_TOGGLE_OFF;
108 - break;
109 - case 'toggle_on':
110 - pathData = PATH_TOGGLE_ON;
111 - break;
104 case 'undo':
105 pathData = PATH_UNDO;
106 break;
@@ -220,12 +212,6 @@ const PATH_SETTINGS = `
212 .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
213 `;
214
223 -const PATH_TOGGLE_OFF =
224 - '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';
225 -
226 -const PATH_TOGGLE_ON =
227 - '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';
228 -
215 const PATH_UNDO = `
216 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
217 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z
src/devtools/views/Settings/SettingsContext.js
-1
@@ -251,7 +251,6 @@ function updateThemeVariables(
251 updateStyleHelper(theme, 'color-toggle-background-on', documentElements);
252 updateStyleHelper(theme, 'color-toggle-background-off', documentElements);
253 updateStyleHelper(theme, 'color-toggle-text', documentElements);
254 - updateStyleHelper(theme, 'color-toggle-text', documentElements);
254 updateStyleHelper(theme, 'color-tooltip-background', documentElements);
255 updateStyleHelper(theme, 'color-tooltip-text', documentElements);
256
src/devtools/views/hooks.js
+1 -1
@@ -50,7 +50,7 @@ export function useLocalStorage<T>(
50 console.log(error);
51 }
52 if (typeof initialValue === 'function') {
53 - return (initialValue: any)();
53 + return ((initialValue: any): () => T)();
54 } else {
55 return initialValue;
56 }