Skip to content

Commit edc46d7

Browse files
author
Brian Vaughn
committed
Misc Flow and import fixes
1. Fixed all reported Flow errors 2. Added a few missing package declarations 3. Deleted ReactDebugHooks fork in favor of react-debug-tools
1 parent 08743b1 commit edc46d7

File tree

23 files changed

+146
-767
lines changed

23 files changed

+146
-767
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,14 @@ const Dispatcher: DispatcherType = {
253253

254254
// Inspect
255255

256-
type HooksNode = {
256+
export type HooksNode = {
257257
id: number | null,
258258
isStateEditable: boolean,
259259
name: string,
260260
value: mixed,
261261
subHooks: Array<HooksNode>,
262262
};
263-
type HooksTree = Array<HooksNode>;
263+
export type HooksTree = Array<HooksNode>;
264264

265265
// Don't assume
266266
//

packages/react-devtools-core/src/standalone.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ function startServer(port?: number = 8097) {
300300
close: function() {
301301
connected = null;
302302
onDisconnected();
303-
clearTimeout(startServerTimeoutID);
303+
if (startServerTimeoutID !== null) {
304+
clearTimeout(startServerTimeoutID);
305+
}
304306
server.close();
305307
httpServer.close();
306308
},

packages/react-devtools-extensions/flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
declare module 'events' {
3+
declare module 'node-events' {
44
declare class EventEmitter<Events: Object> {
55
addListener<Event: $Keys<Events>>(
66
event: Event,

packages/react-devtools-shared/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"clipboard-js": "^0.3.6",
99
"lodash.throttle": "^4.1.1",
1010
"memoize-one": "^3.1.1",
11+
"node-events": "npm:events@^3.0.0",
1112
"react-virtualized-auto-sizer": "^1.0.2"
1213
}
1314
}

packages/react-devtools-shared/src/__tests__/storeOwners-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
const { printOwnersList } = require('./storeSerializer');
3+
const { printOwnersList } = require('../devtools/utils');
44

55
describe('Store owners list', () => {
66
let React;
Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { printStore } from 'react-devtools-shared/src/devtools/utils'
2+
13
// test() is part of Jest's serializer API
24
export function test(maybeStore) {
35
// It's important to lazy-require the Store rather than imported at the head of the module.
@@ -11,74 +13,6 @@ export function print(store, serialize, indent) {
1113
return printStore(store);
1214
}
1315

14-
export function printElement(element, includeWeight = false) {
15-
let prefix = ' ';
16-
if (element.children.length > 0) {
17-
prefix = element.isCollapsed ? '▸' : '▾';
18-
}
19-
20-
let key = '';
21-
if (element.key !== null) {
22-
key = ` key="${element.key}"`;
23-
}
24-
25-
let hocs = '';
26-
if (element.hocDisplayNames !== null) {
27-
hocs = ` [${element.hocDisplayNames.join('][')}]`;
28-
}
29-
30-
let suffix = '';
31-
if (includeWeight) {
32-
suffix = ` (${element.isCollapsed ? 1 : element.weight})`;
33-
}
34-
35-
return `${' '.repeat(element.depth + 1)}${prefix} <${element.displayName ||
36-
'null'}${key}>${hocs}${suffix}`;
37-
}
38-
39-
export function printOwnersList(elements, includeWeight = false) {
40-
return elements
41-
.map(element => printElement(element, includeWeight))
42-
.join('\n');
43-
}
44-
4516
// Used for Jest snapshot testing.
4617
// May also be useful for visually debugging the tree, so it lives on the Store.
47-
export function printStore(store, includeWeight = false) {
48-
const snapshotLines = [];
49-
50-
let rootWeight = 0;
51-
52-
store.roots.forEach(rootID => {
53-
const { weight } = store.getElementByID(rootID);
54-
55-
snapshotLines.push('[root]' + (includeWeight ? ` (${weight})` : ''));
56-
57-
for (let i = rootWeight; i < rootWeight + weight; i++) {
58-
const element = store.getElementAtIndex(i);
59-
60-
if (element == null) {
61-
throw Error(`Could not find element at index ${i}`);
62-
}
63-
64-
snapshotLines.push(printElement(element, includeWeight));
65-
}
66-
67-
rootWeight += weight;
68-
});
69-
70-
// Make sure the pretty-printed test align with the Store's reported number of total rows.
71-
if (rootWeight !== store.numElements) {
72-
throw Error(
73-
`Inconsistent Store state. Individual root weights (${rootWeight}) do not match total weight (${
74-
store.numElements
75-
})`
76-
);
77-
}
78-
79-
// If roots have been unmounted, verify that they've been removed from maps.
80-
// This helps ensure the Store doesn't leak memory.
81-
store.assertExpectedRootMapSizes();
82-
83-
return snapshotLines.join('\n');
84-
}
18+
export { printStore };

packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { BackendBridge } from 'react-devtools-shared/src/bridge';
77
import type { RendererID } from '../types';
88
import type { StyleAndLayout } from './types';
99

10-
export type ResolveNativeStyle = (stylesheetID: number) => ?Object;
10+
export type ResolveNativeStyle = (stylesheetID: any) => ?Object;
1111

1212
export default function setupNativeStyleEditor(
1313
bridge: BackendBridge,
@@ -136,9 +136,8 @@ function measureStyle(
136136
);
137137
return;
138138
}
139-
const margin = resolveBoxStyle('margin', resolvedStyle) || EMPTY_BOX_STYLE;
140-
const padding =
141-
resolveBoxStyle('padding', resolvedStyle) || EMPTY_BOX_STYLE;
139+
const margin = resolvedStyle != null && resolveBoxStyle('margin', resolvedStyle) || EMPTY_BOX_STYLE;
140+
const padding = resolvedStyle != null && resolveBoxStyle('padding', resolvedStyle) || EMPTY_BOX_STYLE;
142141
bridge.send(
143142
'NativeStyleEditor_styleAndLayout',
144143
({

0 commit comments

Comments
 (0)