Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Experimental WebAPI
GitHub

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 withAPI 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 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:

typescrollBehavior=
| @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 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.

typehtmlSpanElement= {
...htmlElement,
}

Properties spreading is not possible in recursive types! When a circularreference is detected, the base properties are duplicated instead.

typerecnode= {
nodeName:string
// ... more properties
}
andelement= {
// duplicated property from node
nodeName:string
// ... more properties
}

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.

typeeventListenerOptions= {mutablecapture?:bool}
// Model after the documentation of
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#options
typeaddEventListenerOptions= {
...eventListenerOptions,
mutablepassive?:bool,
mutableonce?:bool,
mutablesignal?:abortSignal,
}

[8]ページ先頭

©2009-2025 Movatter.jp