From ef55a9f7a81430f196e23eb1417644bbfa6e4d88 Mon Sep 17 00:00:00 2001 From: ri7nz Date: Sat, 29 May 2021 13:01:22 +0800 Subject: [PATCH] feat(worker): add bindings for web workers API --- rescript-worker/CHANGELOG.md | 1 + rescript-worker/README.md | 43 ++++++++++++++++++++++++++++++++++ rescript-worker/bsconfig.json | 11 +++++++++ rescript-worker/package.json | 29 +++++++++++++++++++++++ rescript-worker/src/Worker.js | 2 ++ rescript-worker/src/Worker.res | 7 ++++++ 6 files changed, 93 insertions(+) create mode 100644 rescript-worker/CHANGELOG.md create mode 100644 rescript-worker/README.md create mode 100644 rescript-worker/bsconfig.json create mode 100644 rescript-worker/package.json create mode 100644 rescript-worker/src/Worker.js create mode 100644 rescript-worker/src/Worker.res diff --git a/rescript-worker/CHANGELOG.md b/rescript-worker/CHANGELOG.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/rescript-worker/CHANGELOG.md @@ -0,0 +1 @@ + diff --git a/rescript-worker/README.md b/rescript-worker/README.md new file mode 100644 index 0000000..cb0e4d6 --- /dev/null +++ b/rescript-worker/README.md @@ -0,0 +1,43 @@ +# rescript-worker +> Zero-cost bindings for Web API [Worker](https://www.w3.org/TR/workers) + + +## Installation + +Run the following in your favorit console: +```console +> yarn add rescript-worker +``` + +**OR** + +```console +> npm install --save rescript-worker +``` + +Then, add `rescript-worker` in your `bsconfig.json`: + +```diff +-- "bs-dependencies": [], +++ "bs-dependencies": ["rescript-worker"], +``` + +## Usage + +```rescript +// construct +let abortController = AbortController.new() + +let worker = Worker.new("ourworker.js") +let workerWithOptions = Worker.newWithOptions("",{"optKey": "optValue"}) + +``` + +Or you can check this [**examples**](https://github.com/ri7nz/rescript-libs/tree/main/examples/dev/dev__worker.res). + +## API +> (WIP) + +## Reference +* https://www.w3.org/TR/workers +* https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API diff --git a/rescript-worker/bsconfig.json b/rescript-worker/bsconfig.json new file mode 100644 index 0000000..1aa310a --- /dev/null +++ b/rescript-worker/bsconfig.json @@ -0,0 +1,11 @@ +{ + "name": "rescript-worker", + "sources": { + "dir": "src", + "subdirs": true + }, + "package-specs": { + "module": "es6", + "in-source": true + } +} diff --git a/rescript-worker/package.json b/rescript-worker/package.json new file mode 100644 index 0000000..260076a --- /dev/null +++ b/rescript-worker/package.json @@ -0,0 +1,29 @@ +{ + "name": "rescript-worker", + "version": "0.0.1", + "description": "zero-cost bind for Web Workers API", + "keywords": [ + "web-api", + "rescript", + "web-worker", + "worker", + "Web-Workers-API" + ], + "author": "ri7nz ", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/ri7nz/rescript-libs.git", + "directory": "rescript-worker" + }, + "scripts": { + "start": "rescript build -w", + "build": "rescript build -with-deps" + }, + "bugs": { + "url": "https://github.com/ri7nz/rescript-libs/issues" + }, + "devDependencies": { + "rescript": "9.1.1" + } +} diff --git a/rescript-worker/src/Worker.js b/rescript-worker/src/Worker.js new file mode 100644 index 0000000..d856702 --- /dev/null +++ b/rescript-worker/src/Worker.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/rescript-worker/src/Worker.res b/rescript-worker/src/Worker.res new file mode 100644 index 0000000..cff3c8d --- /dev/null +++ b/rescript-worker/src/Worker.res @@ -0,0 +1,7 @@ +type t + +@new +external new: string => t = "Worker" + +@new +external newWithOptions: (string, {..}) => t = "Worker"