Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Add bindings for Navigator #194

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
### 0.19.1
### 0.20.0
* Add bindings for `Navigator`

### 0.19.1
* Removed dev dependency on `bsdoc` to allow smooth installs on non-Mac
OS

### 0.19.0

* Added bindings to `ReadableStream`
* Added `Webapi.Url.makeWith`
* Deprecated `Webapi.Url.makeWithBase` in favor of `Webapi.Url.makeWith`
Expand Down
47 changes: 47 additions & 0 deletions lib/js/tests/Webapi/Dom/Webapi__Dom__Navigator__test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';


var $$navigator = window.navigator;

$$navigator.clipboard;

$$navigator.cookieEnabled;

$$navigator.geolocation;

$$navigator.maxTouchPoints;

$$navigator.mediaDevices;

$$navigator.serviceWorker;

$$navigator.vendor;

$$navigator.registerProtocolHandler("web+burger", "https://burgers.example.com/?burger=%s", "Burger handler");

$$navigator.sendBeacon("/log", "a whole lotta burgers");

$$navigator.vibrate(200);

$$navigator.vibrate([
100,
30,
100,
30,
100,
30,
200,
30,
200,
30,
200,
30,
100,
30,
100,
30,
100
]);

exports.$$navigator = $$navigator;
/* navigator Not a pure module */
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bs-webapi",
"version": "0.19.1",
"version": "0.20.0",
"description": "Reason + BuckleScript bindings to DOM",
"repository": {
"type": "git",
Expand Down
65 changes: 65 additions & 0 deletions src/Webapi/Dom/Webapi__Dom__Navigator.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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 clipboard : t => clipboard = "";
// [@bs.get] external connection : t => networkConnection = ""; /** experimental */
[@bs.get] external cookieEnabled : t => bool = "";
// [@bs.get] external credentials : t => credentialsContainer = ""; /** experimental */
// [@bs.get] external deviceMemory : t => float = ""; /** experimental */
// [@bs.get] external doNotTrack : t => string = ""; /** experimental */
[@bs.get] external geolocation : t => geolocation = "";
// [@bs.get] external keyboard : t => keyboard = ""; /** experimental */
// [@bs.get] external locks : t => lockManager = ""; /** experimental */
[@bs.get] external maxTouchPoints : t => int = "";
// [@bs.get] external mediaCapabilities : t => mediaCapabilities = ""; /** experimental */
[@bs.get] external mediaDevices : t => mediaDevices = "";
// [@bs.get] external mediaSession : t => mediaSession = ""; /** experimental */
// [@bs.get] external permissions : t => permissions = ""; /** experimental */
// [@bs.get] external presentation : t => presentation = ""; /** experimental */
[@bs.get] external serviceWorker : t => serviceWorkerContainer = "";
[@bs.get] external vendor : t => string = "";
// [@bs.get] external vendorSub : t => string = ""; /** non-standard */
// [@bs.get] external wakeLock : t => wakeLock = ""; /** experimental */
// [@bs.get] external webdriver : t => bool = ""; /** experimental */
// [@bs.get] external xr : t => xr = ""; /** experimental */

// [@bs.send.pipe : t] external canShare : shareOptions => bool = ""; /** experimental */
// [@bs.send.pipe : t] external getGamePads : unit => array(gamePad) = ""; /** experimental */
[@bs.send.pipe : t] external registerProtocolHandler : (string, string, string) => unit = "";
[@bs.send.pipe : t] external requestMediaKeySystemAccess : (string, array(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) = ""; /** experimental */
[@bs.send.pipe : t] external vibrate : int => bool = "vibrate";
[@bs.send.pipe : t] external vibrateArray : array(int) => bool = "vibrate";
2 changes: 1 addition & 1 deletion src/Webapi/Dom/Webapi__Dom__Window.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 navigator = Webapi__Dom__Navigator.t;
type personalbar; /* "bar object" */
type screen;
type scrollbars; /* "bar object" */
Expand Down
4 changes: 4 additions & 0 deletions src/Webapi/Webapi__Dom.re
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ module MouseEvent = Webapi__Dom__MouseEvent;
module MutationObserver = Webapi__Dom__MutationObserver;
module MutationRecord = Webapi__Dom__MutationRecord;
module NamedNodeMap = Webapi__Dom__NamedNodeMap;

/** @since 0.20.0 */
module Navigator = Webapi__Dom__Navigator;

module Node = Webapi__Dom__Node;
module NodeFilter = Webapi__Dom__NodeFilter;
module NodeIterator = Webapi__Dom__NodeIterator;
Expand Down
15 changes: 15 additions & 0 deletions tests/Webapi/Dom/Webapi__Dom__Navigator__test.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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


let navigator = Window.navigator(window);
let _ = Navigator.clipboard(navigator);
let _ = Navigator.cookieEnabled(navigator);
let _ = Navigator.geolocation(navigator);
let _ = Navigator.maxTouchPoints(navigator);
let _ = Navigator.mediaDevices(navigator);
let _ = Navigator.serviceWorker(navigator);
let _ = Navigator.vendor(navigator);

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