Improve Bridge Flow types
Closed this issue · 0 comments
bvaughn commented
I recently added Flow coverage for adding and removing listeners from EventEmitter
sub classes. We could similarly improve Flow support for the Bridge
by typing the send
method:
type BridgeEvents = {|
...
|};
export default class Bridge extends EventEmitter<BridgeEvents> {
send<EventName: $Keys<BridgeEvents>>(
event: EventName,
...payload: $ElementType<BridgeEvents, EventName>
) {
// ...
}
}
Proof of concept in Flow REPL.
We might be able to further improve Flow types by specifying which subset of messages a Bridge
instance is authorized to send vs receive (by splitting up the event generics into two exports). This could enforce that only the frontend can send e.g. inspectElement
and only the backend can send e.g. inspectedElement
messages.
type BackendToFrontendEvents = {|
...
|};
type FrontendToBackendEvents = {|
...
|};
export class BackendBridge<BackendToFrontendEvents, FrontendToBackendEvents> {
// ...
}
export class FrontendBridge<FrontendToBackendEvents, BackendToFrontendEvents> {
// ...
}
I'd like to wait until the RN support PR has landed, since this may be a noisy change.