bvaughn/react-devtools-experimental

Add Flow types to Bridge messages

bvaughn opened this issue · 3 comments

It is currently too easy to mismatch types between what we send through the Bridge and what we listen for (addListener). We should harden these types by specifically enumerating all possible combinations.

Looks like the current set of bridge message we are sending is:

  • captureScreenshot
  • clearHighlightedElementInDOM
  • getOwnersList
  • getProfilingDataComponentFilters
  • getProfilingStatus
  • highlightElementInDOM
  • init
  • inspectElement
  • inspectedElement
  • isBackendStorageAPISupported
  • logElementToConsole
  • operations
  • ownersList
  • overrideContext
  • overrideHookState
  • overrideProps
  • overrideState
  • overrideSuspense
  • profilingData
  • profilingStat
  • reloadAndProfile
  • reloadAppForProfiling
  • screenshotCaptured
  • selectElement
  • selectFiber
  • startInspectingDOM
  • startProfiling
  • stopInspectingDOM
  • stopProfiling
  • syncSelectionFromNativeElementsPanel
  • syncSelectionToNativeElementsPanel
  • update
  • viewElementSource

I think we could improve our current Flow definition for the EventEmitter type to be one that requires explicit event parameters:

declare module "events" {
  declare class EventEmitter<Events: Object> {
    addListener<Event: $Keys<Events>>(
      event: Event,
      listener: (...$ElementType<Events, Event>) => any
    ): void;
    emit: <Event: $Keys<Events>>(
      event: Event,
      ...$ElementType<Events, Event>
    ) => void;
    removeListener(event: $Keys<Events>, listener: Function): void;
    removeAllListeners(event?: $Keys<Events>): void;
  }

  declare export default typeof EventEmitter;
}