All Projects → reasonml-community → Bs Webapi Incubator

reasonml-community / Bs Webapi Incubator

Licence: mit
BuckleScript bindings to the DOM and other Web APIs

Programming Languages

javascript
184084 projects - #8 most used programming language
ocaml
1615 projects
reason
219 projects
bucklescript
41 projects

Labels

Projects that are alternatives of or similar to Bs Webapi Incubator

simplesquirrel
Yet another simple binding in C++11 for Squirrel scripting language
Stars: ✭ 37 (-87.54%)
Mutual labels:  bindings
lz4-napi
Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex.
Stars: ✭ 29 (-90.24%)
Mutual labels:  bindings
napi.zig
tiny and fast napi bindings for zig
Stars: ✭ 53 (-82.15%)
Mutual labels:  bindings
vulkan
Vulkan bindings for Nim
Stars: ✭ 15 (-94.95%)
Mutual labels:  bindings
vsphere-automation-sdk-rest
REST (Postman and JavaScript) samples and API reference documentation for vSphere using the VMware REST API
Stars: ✭ 194 (-34.68%)
Mutual labels:  bindings
rescript-material-ui
ReScript bindings for Material-UI
Stars: ✭ 222 (-25.25%)
Mutual labels:  bindings
zydis-py
Zydis Python Bindings (Work In Progress)
Stars: ✭ 21 (-92.93%)
Mutual labels:  bindings
Disgord
Go module for interacting with the documented Discord's bot interface; Gateway, REST requests and voice
Stars: ✭ 277 (-6.73%)
Mutual labels:  bindings
rust-lang-interop
Rust language interoperability with other languages - C, C++ etc.
Stars: ✭ 53 (-82.15%)
Mutual labels:  bindings
renderdoc-rs
RenderDoc application bindings for Rust
Stars: ✭ 28 (-90.57%)
Mutual labels:  bindings
pmod
Native cross platform library with language projection support for native code.
Stars: ✭ 22 (-92.59%)
Mutual labels:  bindings
directx-d
[DISCONTINUED] DirectX bindings for D
Stars: ✭ 19 (-93.6%)
Mutual labels:  bindings
Binaryen
Binaryen for Swift
Stars: ✭ 15 (-94.95%)
Mutual labels:  bindings
webview
Nim bindings for https://github.com/zserge/webview
Stars: ✭ 91 (-69.36%)
Mutual labels:  bindings
eigenpy
Bindings between Numpy and Eigen using Boost.Python
Stars: ✭ 88 (-70.37%)
Mutual labels:  bindings
TypeScriptXX
🧷 Stay safe! Type-safe scripting for C++ using TypeScriptToLua and CMake with auto-generated declarations.
Stars: ✭ 33 (-88.89%)
Mutual labels:  bindings
uplink-nodejs
NodeJS / typescript bindings for libuplink
Stars: ✭ 20 (-93.27%)
Mutual labels:  bindings
Macdriver
Native Mac APIs for Go
Stars: ✭ 3,582 (+1106.06%)
Mutual labels:  bindings
Crsfml
Crystal bindings to SFML multimedia/game library
Stars: ✭ 274 (-7.74%)
Mutual labels:  bindings
fscalendar-ios-binding
Xamarin Binding Library - FSCalendar for iOS https://github.com/WenchaoD/FSCalendar
Stars: ✭ 12 (-95.96%)
Mutual labels:  bindings

bs-webapi

Experimental bindings to the DOM and other Web APIs.

npm Travis

API docs are available at https://reasonml-community.github.io/bs-webapi-incubator/api/Webapi/ , but documentation comments are sparse as the code mostly just consists of external declarations with type signatures. The bindings generally also correspond very well to the Web APIs they bind to, so using MDN along with GitHub should go a long way.

Installation

npm install bs-webapi

Then add bs-webapi to bs-dependencies in your bsconfig.json. A minimal example:

{
  "name": "my-thing",
  "sources": "src",
  "bs-dependencies": ["bs-webapi"]
}

Usage

See the examples folder

Please only use the modules exposed through the toplevel module Webapi, for example Webapi.Dom.Element. In particular, don't use the 'flat' modules like Webapi__Dom__Element as these are considered private and are not guaranteed to be backwards-compatible.

Some notes on the DOM API

The DOM API is mostly organized into interfaces and relies heavily on inheritance. The ergonomics of the API is also heavily dependent on dynamic typing, which makes it somewhat challenging to implement a thin binding layer that is both safe and ergonomic. To achieve this we employ subtyping and implementation inheritance, concepts which aren't very idiomatic to OCaml (or Reason), but all the more beneficial to understand in order to be able to use these bindings effectively.

Subtyping

The Dom types, and the relationships between them, are actually defined in the Dom module that ships with bs-platform (Source code), where you'll find a bunch of types that look like this:

type _element('a);
type element_like('a) = node_like(_element('a));
type element = element_like(_baseClass);

This is subtyping implemented with abstract types and phantom arguments. The details of how this works isn't very important (but see #23 for a detailed explanation of how exactly this trickery works) in order to just use them, but there are a few things you should know:

  • If you expand the alias of a concrete DOM type, you'll discover it's actually a list of abstract types. e.g. element expands to _baseClass _element _node _eventTarget_like This means element is a subtype of _element, _node and _eventTarget_like.
  • The _like type are "open" (because they have a type variable). This means that a function accepting an 'a element_like will accept any "supertype" of element_like. A function accepting just an element will only accept an element (Technically element is actually a "supertype" of element_like too).

This system works exceptionally well, but has one significant flaw: It makes type errors even more complicated than they normally are. If you know what to look for it's not that bad, but unfortunately the formatting of these errors don't make looking for it any easier. We hope to improve that in other ways (see BetterErrors)

Implementation inheritance

If you've looked through the source code a bit, you've likely come across code like this:

include Webapi__Dom__EventTarget.Impl({ type nonrec t = t });
include Webapi__Dom__Node.Impl({ type nonrec t = t });
include Webapi__Dom__ParentNode.Impl({ type nonrec t = t });
include Webapi__Dom__NonDocumentTypeChildNode.Impl({ type nonrec t = t });
include Webapi__Dom__ChildNode.Impl({ type nonrec t = t });
include Webapi__Dom__Slotable.Impl({ type nonrec t = t });
include Impl({ type nonrec t = t });

This is the implementation inheritance. Each "inheritable" module defines an "Impl" module where all its exported functions are defined. include Webapi__Dom__Node.Impl { type nonrec t = t }; means that all the functions in Webapi__Dom__Node.Impl should be included in this module, but with the t type of that module replaced by the t type of this one. And that's it, it now has all the functions.

Implementation inheritance is used instead of subtyping to make it easier to understand which functions operate on any given "subject". If you have an element and you need to use a function defined in Node, let's say removeChild you cannot just use Node.removeChild. Instead you need to use Element.removeChild, which you can since Element inherits from Node. As a general rule, always use the function in the module corresponding to the type you have. You'll find this makes it very easy to see what types you're dealing with just by reading the code.

Changes

See CHANGELOG.md.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].