![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Experimental bindings to the DOM and other Web APIs.
The bindings are currently undocumented, but as the code mostly just consists of external declarations with type signatures, the code itself is fairly self-documenting. 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.
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"]
}
See the examples folder
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.
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:
element
expands to _baseClass _element _node _eventTarget_like
This means element
is a subtype of _element
, _node
and _eventTarget_like
._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)
If you've looked through the source code a bit, you've likely come across code like this:
include EventTargetRe.Impl({ type nonrec t = t });
include NodeRe.Impl({ type nonrec t = t });
include ParentNodeRe.Impl({ type nonrec t = t });
include NonDocumentTypeChildNodeRe.Impl({ type nonrec t = t });
include ChildNodeRe.Impl({ type nonrec t = t });
include SlotableRe.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 NodeRe.Impl { type nonrec t = t };
means that all the functions in NodeRe.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.
FocusEvent.relatedTarget
to return option
HtmlFormElement
and HtmlInputElement
StorageEvent.oldValue
and StorageEvent.newValue
. They should be nullable
, but were not.Url
and UrlSearchParams
Webapi.File.Url
in favor of Webapi.Url
EventTarget.dispatchEvent
now take a Dom.event_like(_)
instead of just Dom.event
, so it will accept any event subtype.Window.pageXOffset
, pageYOffset
, scrollX
, scrollY
, scrollLeft
and scrollTop
now return float
s instead of int
s, and Window.scroll
, scrollBy
, scrollTo
, setScrollLeft
and setScrollTop
take float
s instead of int
sHtmlElement.offsetParent
now returns an option
Selection.anchorNode
and Selection.focusNode
now return option
sElement.closest
now returns an option
HtmlElement
and its ancestors to HtmlImageElement
HtmlImageElement.onload
HtmlImageElement.src
and HtmlImageElement.getSrc
, breaking the APIHtmlImageElement
Document.docType
to Document.doctype
to fix #95bs-platform@3.0.0
. If your app isn't using that version, then don't upgrade to 0.9.0
; otherwise, please do!EventTarget.unsafeAsDocument
, EventTarget.unsafeAsElement
and EventTarget.unsafeAsWindow
functionsBs_webapi
module`EventTarget
, e.g. EventTarget.addMouseMoveListener(mouseEvent => ...)
requestCancellableAnimationFrame
and cancelAnimationFrame
@bs.return
annotations causing type unsoundnessinsertPosition
typeDom.HtmlImageElement
, File
and File.Url
HtmlElement.offsetParent
returning int
instead of Dom.Element
Webapi
module, Deprecated Bs_webapi
Document.unsafeAshtmlDocument
, Element.unsafeAsHtmlElement
. Deprecated Document.asHtmlDocument
, Element.asHtmlElement
, HtmlEleement.ofElement
.Dom.history
and Dom.location
to use window
instead of document
HtmlElement.ofElement
bs-platform
as Dom.Storage
ReasonJs
namespace. Use Bs_webapi
insteadFAQs
Reason + BuckleScript bindings to DOM
The npm package bs-webapi receives a total of 561 weekly downloads. As such, bs-webapi popularity was classified as not popular.
We found that bs-webapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.