Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/Webapi/Dom/Webapi__Dom__Navigator.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
open Js.Typed_array;


type t;

type clipboard;
type networkConnection;
type credentialsContainer;
type geolocation;
type mediaDevices;
type mediaSession;
type serviceWorkerContainer;
type xr;
type mediaKeySystemAccess;
type mediaKeySystemConfiguration;
type shareOptions;

[@bs.get] external buildID : t => string = "";
[@bs.get] external clipboard : t => clipboard = "";
[@bs.get] external connection : t => networkConnection = "";
[@bs.get] external cookieEnabled : t => bool = "";
[@bs.get] external credentials : t => credentialsContainer = "";
[@bs.get] external deviceMemory : t => float = "";
[@bs.get] external geolocation : t => geolocation = "";
[@bs.get] external language : t => string = "";
[@bs.get] external maxTouchPoints : t => int = "";
[@bs.get] external mediaDevices : t => mediaDevices = "";
[@bs.get] external mediaSession : t => mediaSession = "";
[@bs.get] external onLine : t => bool = "";
[@bs.get] external oscpu : t => string = "";
[@bs.get] external platform : t => string = "";
[@bs.get] external productSub : t => string = "";
[@bs.get] external serviceWorker : t => serviceWorkerContainer = "";
[@bs.get] external vendor : t => string = "";
[@bs.get] external vendorSub : t => string = "";
[@bs.get] external webdriver : t => bool = "";
[@bs.get] external xr : t => xr = "";

[@bs.send.pipe : t] external canShare : shareOptions => bool = "";
[@bs.send.pipe : t] external registerProtocolHandler : (string, string, string) => unit = "";
[@bs.send.pipe : t] external requestMediaKeySystemAccess : (string, list(mediaKeySystemConfiguration)) => Js.Promise.t(mediaKeySystemAccess) = "";
[@bs.send.pipe : t] external sendBeacon : (
string,
[@bs.unwrap] [
| `ArrayBuffer(ArrayBuffer.t)
| `Int8Array(Int8Array.t)
| `Uint8Array(Uint8Array.t)
| `Uint8ClampedArray(Uint8ClampedArray.t)
| `Int16Array(Int16Array.t)
| `Uint16Array(Uint16Array.t)
| `Int32Array(Int32Array.t)
| `Uint32Array(Uint32Array.t)
| `Float32Array(Float32Array.t)
| `Float64Array(Float64Array.t)
| `DataView(DataView.t)
| `Blob(Webapi__Blob.t)
| `FormData(Fetch.FormData.t)
| `URLSearchParams(Webapi__Url.URLSearchParams.t)
| `String(string)
]) => bool = "";
[@bs.send.pipe : t] external share : shareOptions => Js.Promise.t(unit) = "";
[@bs.send.pipe : t] external vibrate : (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are only two types of allowed parameters here, can you use two different bindings i.e. vibrate and vibrateArray? That's the typical style used in bs-webapi, and I recommended the @bs.unwrap style for sendBeacon because it takes so many different types that it would have exploded the number of bindings.

[@bs.unwrap] [
| `Int(int)
| `IntList(list(int))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For vibrateArray we need to ensure that the parameter type is array(int), because a Reason array corresponds to a JavaScript array. It can't be a list.

]) => bool = "";
3 changes: 1 addition & 2 deletions src/Webapi/Dom/Webapi__Dom__Window.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ type frameList; /* array-like, WindowProxy? */
type idleDeadline; /* Cooperative Scheduling of Background Tasks */
type locationbar; /* "bar object" */
type menubar; /* "bar object" */
type navigator;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting this type will break backward-compatibility, so instead can you alias it to the newly-introduced Webapi__Dom__Navigator.t type and deprecate the alias, thx

type personalbar; /* "bar object" */
type screen;
type scrollbars; /* "bar object" */
Expand Down Expand Up @@ -39,7 +38,7 @@ module Impl = (T: {type t;}) => {
[@bs.get] external menubar : t_window => menubar = "";
[@bs.get] external name : t_window => string = "";
[@bs.set] external setName : (t_window, string) => unit = "name";
[@bs.get] external navigator : t_window => navigator = "";
[@bs.get] external navigator : t_window => Webapi__Dom__Navigator.t = "";
[@bs.get] [@bs.return nullable] external opener : t_window => option(Dom.window) = "";
[@bs.get] external outerWidth : t_window => int = "";
[@bs.get] external outerHeight : t_window => int = "";
Expand Down
2 changes: 2 additions & 0 deletions src/Webapi/Webapi__Dom.re
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module MouseEvent = Webapi__Dom__MouseEvent;
module MutationObserver = Webapi__Dom__MutationObserver;
module MutationRecord = Webapi__Dom__MutationRecord;
module NamedNodeMap = Webapi__Dom__NamedNodeMap;
module Navigator = Webapi__Dom__Navigator;
module Node = Webapi__Dom__Node;
module NodeFilter = Webapi__Dom__NodeFilter;
module NodeIterator = Webapi__Dom__NodeIterator;
Expand Down Expand Up @@ -71,6 +72,7 @@ include Webapi__Dom__Types;
[@bs.val] external document : Dom.document = "document";
[@bs.val] [@bs.scope "window"] external history : Dom.history = "history";
[@bs.val] [@bs.scope "window"] external location : Dom.location = "location";
[@bs.val] [@bs.scope "window"] external navigator : Webapi__Dom__Navigator.t = "navigator";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize there are similar bindings above it, but I really don't think Webapi.Dom.navigator is a sensible place to access a Navigator object from. Since the Webapi.Dom.Window.navigator binding already exists, we don't need another one here.



/* Unimplemented interfaces (aka. "The TODO list")
Expand Down
28 changes: 28 additions & 0 deletions tests/Webapi/Dom/Webapi__Dom__Navigator__test.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
open Webapi.Dom;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing these tests. I know it's a bit annoying, but can you also check in the compiled test output? You'll need to do:

git add --force lib/js/tests/Webapi/Dom/Webapi__Dom__Navigator__test.js

open Navigator;

let _ = buildID(navigator);
let _ = clipboard(navigator);
let _ = connection(navigator);
let _ = cookieEnabled(navigator);
let _ = credentials(navigator);
let _ = deviceMemory(navigator);
let _ = geolocation(navigator);
let _ = language(navigator);
let _ = maxTouchPoints(navigator);
let _ = mediaDevices(navigator);
let _ = mediaSession(navigator);
let _ = onLine(navigator);
let _ = oscpu(navigator);
let _ = platform(navigator);
let _ = productSub(navigator);
let _ = serviceWorker(navigator);
let _ = vendor(navigator);
let _ = vendorSub(navigator);
let _ = webdriver(navigator);
let _ = xr(navigator);

navigator |> registerProtocolHandler("web+burger", "https://burgers.example.com/?burger=%s", "Burger handler");
navigator |> sendBeacon("/log", `String("a whole lotta burgers"));
navigator |> vibrate(`Int(200));
navigator |> vibrate(`IntList([100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]));