Tidied up Flow types for Bridge and Store
Brian Vaughn committed
Feb 14, 2019 at 13:32 UTC
9cfa25bdccf1d04f20189ee745a80501ffadd7b1
6 files changed
+15
-16
src/backend/agent.js
+1
-1
@@ -31,7 +31,7 @@ export default class Agent extends EventEmitter {
31
bridge.addListener('shutdown', this.shutdown);
32
33
// TODO Listen to bridge for things like selection.
34
- // bridge.on('...'), this...);
34
+ // bridge.addListener('...'), this...);
35
}
36
37
highlightElementInDOM = ({
src/backend/types.js
+2
-1
@@ -48,6 +48,7 @@ export type RendererInterface = {
48
getNativeFromReactElement?: ?(component: Fiber) => ?NativeType,
49
getReactElementFromNative?: ?(component: NativeType) => ?Fiber,
50
handleCommitFiberRoot: (fiber: Object) => void,
51
+ handleCommitFiberUnmount: (fiber: Object) => void,
52
inspectElement: (id: number) => InspectedElement | null,
53
renderer: ReactRenderer | null,
54
selectElement: (id: number) => void,
@@ -63,7 +64,7 @@ export type Hook = {
64
65
emit: (evt: string, data: any) => void,
66
getFiberRoots: (rendererID: RendererID) => Set<Object>,
66
- inject: (renderer: ReactRenderer) => string | null,
67
+ inject: (renderer: ReactRenderer) => number | null,
68
on: (evt: string, handler: Handler) => void,
69
off: (evt: string, handler: Handler) => void,
70
reactDevtoolsAgent?: ?Object,
src/devtools/store.js
+4
-4
@@ -55,8 +55,8 @@ export default class Store extends EventEmitter {
55
debug('constructor', 'subscribing to Bridge');
56
57
this._bridge = bridge;
58
- this._bridge.on('operations', this.onBridgeOperations);
59
- this._bridge.on('shutdown', this.onBridgeShutdown);
58
+ this._bridge.addListener('operations', this.onBridgeOperations);
59
+ this._bridge.addListener('shutdown', this.onBridgeShutdown);
60
}
61
62
get numElements(): number {
@@ -405,8 +405,8 @@ export default class Store extends EventEmitter {
405
onBridgeShutdown = () => {
406
debug('onBridgeShutdown', 'unsubscribing from Bridge');
407
408
- this._bridge.off('operations', this.onBridgeOperations);
409
- this._bridge.off('shutdown', this.onBridgeShutdown);
408
+ this._bridge.removeListener('operations', this.onBridgeOperations);
409
+ this._bridge.removeListener('shutdown', this.onBridgeShutdown);
410
};
411
412
// DEBUG
src/devtools/views/Settings.css
-1
@@ -1,6 +1,5 @@
1
.Settings {
2
width: 100%;
3
- height: 100%;
3
padding: 0.5rem;
4
display: flex;
5
flex-direction: column;
src/hook.js
+3
-4
@@ -7,12 +7,12 @@
7
* @flow
8
*/
9
10
-import type { Hook } from './types';
10
+import type { Hook } from 'src/backend/types';
11
12
declare var window: any;
13
14
-export function installHook(target: any): Hook {
15
- if (target.hasOwnProperty('__REACT_DEVTOOLS_GLOBAL_HOOK__')) return;
14
+export function installHook(target: any): Hook | null {
15
+ if (target.hasOwnProperty('__REACT_DEVTOOLS_GLOBAL_HOOK__')) return null;
16
17
function detectReactBuildType(renderer) {
18
try {
@@ -124,7 +124,6 @@ export function installHook(target: any): Hook {
124
}
125
126
function onCommitFiberUnmount(rendererID, fiber) {
127
- // TODO: can we use hook for roots too?
127
const rendererInterface = rendererInterfaces.get(rendererID);
128
if (rendererInterface != null) {
129
rendererInterface.handleCommitFiberUnmount(fiber);
src/types.js
+5
-5
@@ -1,10 +1,10 @@
1
// @flow
2
3
-// TODO
4
-export type Bridge = any;
5
-
6
-// TODO
7
-export type Hook = any;
3
+export type Bridge = {
4
+ addListener(type: string, callback: Function): void,
5
+ removeListener(type: string, callback: Function): void,
6
+ send(type: string, data?: any): void,
7
+};
8
9
export type Wall = {|
10
listen: (fn: Function) => void,