Skip to content

API Module Structure

The bindings are organized by the Web API they represent. Each API has its interfaces and auxiliary types in a module named after the API, suffixed with API to prevent collisions with the type module.

  • package.json
  • Directorysrc
    • DOMAPI.res
    • DirectoryDOMAPI
      • HTMLElement.res

Within the API module, the structure is roughly as follows:

  • Enum Types
  • Interfaces
  • Auxiliary Types

Enum types

Enum types are used to represent constants in the Web API. They are typically used as arguments to methods or properties. In ReScript terms these are variants:

type scrollBehavior =
| @as("auto") Auto
| @as("instant") Instant
| @as("smooth") Smooth

Enums come first as they are always self-contained and do not depend on other types.

Interfaces

Interfaces are modeled as record types and are the core of the bindings. They represent the properties and methods of the Web API. If an interface inherits from another interface, the base interface is spread into the inheriting interface.

type htmlSpanElement = {
...htmlElement,
}
type rec node = {
nodeName: string
// ... more properties
}
and element = {
// duplicated property from node
nodeName: string
// ... more properties
}

Auxiliary Types

Auxiliary types are used to represent types that are not directly related to the Web API but are used in the bindings. These can occur both before interfaces and after interfaces, depending on the context.

type eventListenerOptions = {mutable capture?: bool}
// Model after the documentation of
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#options
type addEventListenerOptions = {
...eventListenerOptions,
mutable passive?: bool,
mutable once?: bool,
mutable signal?: abortSignal,
}