Skip to content

Commit 4b34a77

Browse files
author
Brian Vaughn
authored
Improve Bridge Flow types (#352)
* Updated local fork of react-window * Updated Fow 97 -> 103 * Lint ignore NPM dist * Improved Bridge Flow types
1 parent 39ad101 commit 4b34a77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1066
-379
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ shells/browser/chrome/build
44
shells/browser/firefox/build
55
shells/browser/shared/build
66
shells/dev/dist
7+
packages/react-devtools-core/dist
78
vendor
89
*.js.snap
910

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"test:chrome": "node ./shells/browser/chrome/test",
6464
"test:firefox": "node ./shells/browser/firefox/test",
6565
"test:standalone": "cd packages/react-devtools && yarn start",
66-
"typecheck": "flow check"
66+
"typecheck": "flow check --show-all-errors"
6767
},
6868
"devEngines": {
6969
"node": "10.x || 11.x"
@@ -119,7 +119,7 @@
119119
"fbjs": "0.5.1",
120120
"fbjs-scripts": "0.7.0",
121121
"firefox-profile": "^1.0.2",
122-
"flow-bin": "^0.97.0",
122+
"flow-bin": "^0.103.0",
123123
"fs-extra": "^3.0.1",
124124
"gh-pages": "^1.0.0",
125125
"html2canvas": "^1.0.0-alpha.12",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { __DEBUG__ } from 'src/constants';
88
import setupNativeStyleEditor from 'src/backend/NativeStyleEditor/setupNativeStyleEditor';
99
import { getDefaultComponentFilters } from 'src/utils';
1010

11+
import type { BackendBridge } from 'src/bridge';
1112
import type { ComponentFilter } from 'src/types';
1213
import type { DevToolsHook } from 'src/backend/types';
1314
import type { ResolveNativeStyle } from 'src/backend/NativeStyleEditor/setupNativeStyleEditor';
@@ -64,7 +65,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
6465
return;
6566
}
6667

67-
let bridge: Bridge | null = null;
68+
let bridge: BackendBridge | null = null;
6869

6970
const messageListeners = [];
7071
const uri = 'ws://' + host + ':' + port;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import DevTools from 'src/devtools/views/DevTools';
1717
import launchEditor from './launchEditor';
1818
import { __DEBUG__ } from 'src/constants';
1919

20+
import type { FrontendBridge } from 'src/bridge';
2021
import type { InspectedElement } from 'src/devtools/views/Components/types';
2122

2223
installHook(window);
@@ -46,7 +47,7 @@ function setStatusListener(value: StatusListener) {
4647
return DevtoolsUI;
4748
}
4849

49-
let bridge: Bridge | null = null;
50+
let bridge: FrontendBridge | null = null;
5051
let store: Store | null = null;
5152
let root = null;
5253

@@ -83,7 +84,7 @@ function reload() {
8384
root = createRoot(node);
8485
root.render(
8586
createElement(DevTools, {
86-
bridge: ((bridge: any): Bridge),
87+
bridge: ((bridge: any): FrontendBridge),
8788
showTabBar: true,
8889
store: ((store: any): Store),
8990
warnIfLegacyBackendDetected: true,
@@ -166,7 +167,7 @@ function initialize(socket: WebSocket) {
166167
}
167168
},
168169
});
169-
((bridge: any): Bridge).addListener('shutdown', () => {
170+
((bridge: any): FrontendBridge).addListener('shutdown', () => {
170171
socket.close();
171172
});
172173

shells/dev/app/SuspenseTree/index.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// @flow
22

3-
import React, { Suspense, useState } from 'react';
3+
import React, { Fragment, Suspense, useState } from 'react';
44

55
function SuspenseTree() {
66
return (
7-
<>
7+
<Fragment>
88
<h1>Suspense</h1>
99
<h4>Primary to Fallback Cycle</h4>
1010
<PrimaryFallbackTest initialSuspend={false} />
1111
<h4>Fallback to Primary Cycle</h4>
1212
<PrimaryFallbackTest initialSuspend={true} />
1313
<NestedSuspenseTest />
14-
</>
14+
</Fragment>
1515
);
1616
}
1717

@@ -20,7 +20,7 @@ function PrimaryFallbackTest({ initialSuspend }) {
2020
const fallbackStep = useTestSequence('fallback', Fallback1, Fallback2);
2121
const primaryStep = useTestSequence('primary', Primary1, Primary2);
2222
return (
23-
<>
23+
<Fragment>
2424
<label>
2525
<input
2626
checked={suspend}
@@ -33,7 +33,7 @@ function PrimaryFallbackTest({ initialSuspend }) {
3333
<Suspense fallback={fallbackStep}>
3434
{suspend ? <Never /> : primaryStep}
3535
</Suspense>
36-
</>
36+
</Fragment>
3737
);
3838
}
3939

@@ -45,32 +45,32 @@ function useTestSequence(label, T1, T2) {
4545
</button>
4646
);
4747
let allSteps = [
48-
<>{next}</>,
49-
<>
48+
<Fragment>{next}</Fragment>,
49+
<Fragment>
5050
{next} <T1 prop={step}>mount</T1>
51-
</>,
52-
<>
51+
</Fragment>,
52+
<Fragment>
5353
{next} <T1 prop={step}>update</T1>
54-
</>,
55-
<>
54+
</Fragment>,
55+
<Fragment>
5656
{next} <T2 prop={step}>several</T2> <T1 prop={step}>different</T1>{' '}
5757
<T2 prop={step}>children</T2>
58-
</>,
59-
<>
58+
</Fragment>,
59+
<Fragment>
6060
{next} <T2 prop={step}>goodbye</T2>
61-
</>,
61+
</Fragment>,
6262
];
6363
return allSteps[step];
6464
}
6565

6666
function NestedSuspenseTest() {
6767
return (
68-
<>
68+
<Fragment>
6969
<h3>Nested Suspense</h3>
7070
<Suspense fallback={<Fallback1>Loading outer</Fallback1>}>
7171
<Parent />
7272
</Suspense>
73-
</>
73+
</Fragment>
7474
);
7575
}
7676

@@ -118,19 +118,19 @@ function Never() {
118118
throw new Promise(resolve => {});
119119
}
120120

121-
function Fallback1({ prop, ...rest }) {
121+
function Fallback1({ prop, ...rest }: any) {
122122
return <span {...rest} />;
123123
}
124124

125-
function Fallback2({ prop, ...rest }) {
125+
function Fallback2({ prop, ...rest }: any) {
126126
return <span {...rest} />;
127127
}
128128

129-
function Primary1({ prop, ...rest }) {
129+
function Primary1({ prop, ...rest }: any) {
130130
return <span {...rest} />;
131131
}
132132

133-
function Primary2({ prop, ...rest }) {
133+
function Primary2({ prop, ...rest }: any) {
134134
return <span {...rest} />;
135135
}
136136

src/__tests__/bridge-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ describe('Bridge', () => {
1515
const bridge = new Bridge(wall);
1616

1717
// Check that we're wired up correctly.
18-
bridge.send('init');
18+
bridge.send('reloadAppForProfiling');
1919
jest.runAllTimers();
20-
expect(wall.send).toHaveBeenCalledWith('init', undefined, undefined);
20+
expect(wall.send).toHaveBeenCalledWith('reloadAppForProfiling');
2121

2222
// Should flush pending messages and then shut down.
2323
wall.send.mockClear();
2424
bridge.send('update', '1');
2525
bridge.send('update', '2');
2626
bridge.shutdown();
2727
jest.runAllTimers();
28-
expect(wall.send).toHaveBeenCalledWith('update', '1', undefined);
29-
expect(wall.send).toHaveBeenCalledWith('update', '2', undefined);
30-
expect(wall.send).toHaveBeenCalledWith('shutdown', undefined, undefined);
28+
expect(wall.send).toHaveBeenCalledWith('update', '1');
29+
expect(wall.send).toHaveBeenCalledWith('update', '2');
30+
expect(wall.send).toHaveBeenCalledWith('shutdown');
3131

3232
// Verify that the Bridge doesn't send messages after shutdown.
3333
spyOn(console, 'warn');

src/__tests__/inspectedElementContext-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import typeof ReactTestRenderer from 'react-test-renderer';
44
import type { GetInspectedElementPath } from 'src/devtools/views/Components/InspectedElementContext';
5-
import type Bridge from 'src/bridge';
5+
import type { FrontendBridge } from 'src/bridge';
66
import type Store from 'src/devtools/store';
77

88
describe('InspectedElementContext', () => {
99
let React;
1010
let ReactDOM;
1111
let TestRenderer: ReactTestRenderer;
12-
let bridge: Bridge;
12+
let bridge: FrontendBridge;
1313
let store: Store;
1414
let meta;
1515
let utils;

src/__tests__/legacy/inspectElement-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import type { InspectedElementPayload } from 'src/backend/types';
44
import type { DehydratedData } from 'src/devtools/views/Components/types';
5-
import type Bridge from 'src/bridge';
5+
import type { FrontendBridge } from 'src/bridge';
66
import type Store from 'src/devtools/store';
77

88
describe('InspectedElementContext', () => {
99
let React;
1010
let ReactDOM;
1111
let hydrate;
1212
let meta;
13-
let bridge: Bridge;
13+
let bridge: FrontendBridge;
1414
let store: Store;
1515

1616
const act = (callback: Function) => {

src/__tests__/ownersListContext-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import typeof ReactTestRenderer from 'react-test-renderer';
44
import type { Element } from 'src/devtools/views/Components/types';
5-
import type Bridge from 'src/bridge';
5+
import type { FrontendBridge } from 'src/bridge';
66
import type Store from 'src/devtools/store';
77

88
describe('OwnersListContext', () => {
99
let React;
1010
let ReactDOM;
1111
let TestRenderer: ReactTestRenderer;
12-
let bridge: Bridge;
12+
let bridge: FrontendBridge;
1313
let store: Store;
1414
let utils;
1515

src/__tests__/profilerContext-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

33
import typeof ReactTestRenderer from 'react-test-renderer';
4-
import type Bridge from 'src/bridge';
4+
import type { FrontendBridge } from 'src/bridge';
55
import type { Context } from 'src/devtools/views/Profiler/ProfilerContext';
66
import type { DispatcherContext } from 'src/devtools/views/Components/TreeContext';
77
import type Store from 'src/devtools/store';
@@ -10,7 +10,7 @@ describe('ProfilerContext', () => {
1010
let React;
1111
let ReactDOM;
1212
let TestRenderer: ReactTestRenderer;
13-
let bridge: Bridge;
13+
let bridge: FrontendBridge;
1414
let store: Store;
1515
let utils;
1616

0 commit comments

Comments
 (0)