Skip to content

Commit

Permalink
Misc Flow and import fixes
Browse files Browse the repository at this point in the history
1. Fixed all reported Flow errors
2. Added a few missing package declarations
3. Deleted ReactDebugHooks fork in favor of react-debug-tools
  • Loading branch information
Brian Vaughn committed Aug 14, 2019
1 parent 08743b1 commit edc46d7
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 767 deletions.
4 changes: 2 additions & 2 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Expand Up @@ -253,14 +253,14 @@ const Dispatcher: DispatcherType = {

// Inspect

type HooksNode = {
export type HooksNode = {
id: number | null,
isStateEditable: boolean,
name: string,
value: mixed,
subHooks: Array<HooksNode>,
};
type HooksTree = Array<HooksNode>;
export type HooksTree = Array<HooksNode>;

// Don't assume
//
Expand Down
4 changes: 3 additions & 1 deletion packages/react-devtools-core/src/standalone.js
Expand Up @@ -300,7 +300,9 @@ function startServer(port?: number = 8097) {
close: function() {
connected = null;
onDisconnected();
clearTimeout(startServerTimeoutID);
if (startServerTimeoutID !== null) {
clearTimeout(startServerTimeoutID);
}
server.close();
httpServer.close();
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-extensions/flow.js
@@ -1,6 +1,6 @@
// @flow

declare module 'events' {
declare module 'node-events' {
declare class EventEmitter<Events: Object> {
addListener<Event: $Keys<Events>>(
event: Event,
Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools-shared/package.json
Expand Up @@ -8,6 +8,7 @@
"clipboard-js": "^0.3.6",
"lodash.throttle": "^4.1.1",
"memoize-one": "^3.1.1",
"node-events": "npm:events@^3.0.0",
"react-virtualized-auto-sizer": "^1.0.2"
}
}
@@ -1,6 +1,6 @@
// @flow

const { printOwnersList } = require('./storeSerializer');
const { printOwnersList } = require('../devtools/utils');

describe('Store owners list', () => {
let React;
Expand Down
72 changes: 3 additions & 69 deletions packages/react-devtools-shared/src/__tests__/storeSerializer.js
@@ -1,3 +1,5 @@
import { printStore } from 'react-devtools-shared/src/devtools/utils'

// test() is part of Jest's serializer API
export function test(maybeStore) {
// It's important to lazy-require the Store rather than imported at the head of the module.
Expand All @@ -11,74 +13,6 @@ export function print(store, serialize, indent) {
return printStore(store);
}

export function printElement(element, includeWeight = false) {
let prefix = ' ';
if (element.children.length > 0) {
prefix = element.isCollapsed ? '▸' : '▾';
}

let key = '';
if (element.key !== null) {
key = ` key="${element.key}"`;
}

let hocs = '';
if (element.hocDisplayNames !== null) {
hocs = ` [${element.hocDisplayNames.join('][')}]`;
}

let suffix = '';
if (includeWeight) {
suffix = ` (${element.isCollapsed ? 1 : element.weight})`;
}

return `${' '.repeat(element.depth + 1)}${prefix} <${element.displayName ||
'null'}${key}>${hocs}${suffix}`;
}

export function printOwnersList(elements, includeWeight = false) {
return elements
.map(element => printElement(element, includeWeight))
.join('\n');
}

// Used for Jest snapshot testing.
// May also be useful for visually debugging the tree, so it lives on the Store.
export function printStore(store, includeWeight = false) {
const snapshotLines = [];

let rootWeight = 0;

store.roots.forEach(rootID => {
const { weight } = store.getElementByID(rootID);

snapshotLines.push('[root]' + (includeWeight ? ` (${weight})` : ''));

for (let i = rootWeight; i < rootWeight + weight; i++) {
const element = store.getElementAtIndex(i);

if (element == null) {
throw Error(`Could not find element at index ${i}`);
}

snapshotLines.push(printElement(element, includeWeight));
}

rootWeight += weight;
});

// Make sure the pretty-printed test align with the Store's reported number of total rows.
if (rootWeight !== store.numElements) {
throw Error(
`Inconsistent Store state. Individual root weights (${rootWeight}) do not match total weight (${
store.numElements
})`
);
}

// If roots have been unmounted, verify that they've been removed from maps.
// This helps ensure the Store doesn't leak memory.
store.assertExpectedRootMapSizes();

return snapshotLines.join('\n');
}
export { printStore };
Expand Up @@ -7,7 +7,7 @@ import type { BackendBridge } from 'react-devtools-shared/src/bridge';
import type { RendererID } from '../types';
import type { StyleAndLayout } from './types';

export type ResolveNativeStyle = (stylesheetID: number) => ?Object;
export type ResolveNativeStyle = (stylesheetID: any) => ?Object;

export default function setupNativeStyleEditor(
bridge: BackendBridge,
Expand Down Expand Up @@ -136,9 +136,8 @@ function measureStyle(
);
return;
}
const margin = resolveBoxStyle('margin', resolvedStyle) || EMPTY_BOX_STYLE;
const padding =
resolveBoxStyle('padding', resolvedStyle) || EMPTY_BOX_STYLE;
const margin = resolvedStyle != null && resolveBoxStyle('margin', resolvedStyle) || EMPTY_BOX_STYLE;
const padding = resolvedStyle != null && resolveBoxStyle('padding', resolvedStyle) || EMPTY_BOX_STYLE;
bridge.send(
'NativeStyleEditor_styleAndLayout',
({
Expand Down

0 comments on commit edc46d7

Please sign in to comment.