-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add worker api #19
Open
tonyfettes
wants to merge
15
commits into
melange-community:master
Choose a base branch
from
tonyfettes:worker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+156
−0
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4776b5a
feat: add worker api
tonyfettes e4894df
add setOnMessage on Window
tonyfettes d5ce533
export message event
tonyfettes 460eb31
public worker
tonyfettes f719d25
relax postMessage type requirements
tonyfettes 3b702d4
add {add,remove}MessageEventLister
tonyfettes 8637c58
add makeWithUrl
tonyfettes 62b492a
fix: don't apply again when terminating
tonyfettes c26dfd5
feat: add self to Webapi.Dom
tonyfettes ac39fed
fix: remove setOnMessage on Window
tonyfettes b11f137
fix: add missing apis (mainly EventListener)
tonyfettes b9c42c2
feat: {Dedicated,}WorkerGlobalScope
tonyfettes a922ae2
chore: public apis
tonyfettes 3a47d6c
fix: use more detailed self for workerGlobalScope
tonyfettes 6a0b7a0
fix: use array instead of Js.Array.t
tonyfettes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type t = Dom.dedicatedWorkerGlobalScope; | ||
|
||
include Webapi__Dom__WorkerGlobalScope.Impl({ | ||
type nonrec t = t; | ||
}); | ||
|
||
[@mel.get] external name: t => string = "name"; | ||
|
||
[@mel.send.pipe: t] external close: unit = "name"; | ||
|
||
[@mel.send.pipe: t] external postMessage: 'a => unit = "postMessage"; | ||
|
||
[@mel.send.pipe: t] | ||
external postMessageWithTransfers: ('a, array(Webapi__Dom__Window.transferable)) => unit = | ||
"postMessage"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type t = Dom.messageChannel; | ||
|
||
[@mel.new] external make: unit => t = "MessageChannel"; | ||
[@mel.get] external port1: t => Webapi__Dom__MessagePort.t = "port1"; | ||
[@mel.get] external port2: t => Webapi__Dom__MessagePort.t = "port2"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
type t = Dom.messageEvent; | ||
|
||
include Webapi__Dom__Event.Impl({ | ||
type nonrec t = t; | ||
}); | ||
|
||
[@mel.new] external make: string => t = "MessageEvent"; | ||
[@mel.new] | ||
external makeWithOptions: (string, Js.t({..})) => t = "MessageEvent"; | ||
|
||
[@mel.get] external data: t => 'a = "data"; | ||
[@mel.get] external origin: t => string = "origin"; | ||
[@mel.get] external lastEventId: t => string = "lastEventId"; | ||
[@mel.get] | ||
external source: | ||
t => | ||
[@mel.unwrap] [ | ||
| `Window(Dom.window) | ||
| `MessagePort(Dom.messagePort) | ||
| `ServiceWorker(Dom.serviceWorker) | ||
] = | ||
"source"; | ||
[@mel.get] external ports: t => array(Dom.messagePort) = "ports"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
type t = Dom.messagePort; | ||
|
||
include Webapi__Dom__EventTarget.Impl({ | ||
type nonrec t = t; | ||
}); | ||
|
||
[@mel.send.pipe: t] external start: unit => unit = "start"; | ||
[@mel.send.pipe: t] external close: unit => unit = "close"; | ||
|
||
[@mel.send.pipe: t] external postMessage: 'a => unit = "postMessage"; | ||
[@mel.send.pipe: t] external postMessageWithTransfers: ('a, array(Webapi__Dom__Window.transferable)) => unit = "postMessage"; | ||
|
||
[@mel.send.pipe: t] | ||
external addMessageEventListener: | ||
([@mel.as "message"] _, Dom.messageEvent => unit) => unit = | ||
"addEventListener"; | ||
|
||
[@mel.send.pipe: t] | ||
external removeMessageEventListener: | ||
([@mel.as "message"] _, Dom.messageEvent => unit) => unit = | ||
"removeEventListener"; | ||
|
||
[@mel.set] | ||
external setOnMessage: (t, Dom.messageEvent => unit) => unit = "onmessage"; | ||
[@mel.set] | ||
external setOnMessageError: (t, Dom.messageEvent => unit) => unit = | ||
"onmessageerror"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
type t = Dom.worker; | ||
|
||
include Webapi__Dom__EventTarget.Impl({ | ||
type nonrec t = t; | ||
}); | ||
|
||
[@mel.new] external make: string => t = "Worker"; | ||
[@mel.new] external makeWithUrl: Webapi__Url.t => t = "Worker"; | ||
[@mel.send.pipe: t] external postMessage: 'a => unit = "postMessage"; | ||
[@mel.send.pipe: t] external terminate: unit = "terminate"; | ||
|
||
[@mel.send.pipe: t] | ||
external addMessageEventListener: | ||
([@mel.as "message"] _, Dom.messageEvent => unit) => unit = | ||
"addEventListener"; | ||
|
||
[@mel.send.pipe: t] | ||
external removeMessageEventListener: | ||
([@mel.as "message"] _, Dom.messageEvent => unit) => unit = | ||
"removeEventListener"; | ||
|
||
[@mel.send.pipe: t] | ||
external addMessageErrorEventListener: | ||
([@mel.as "message"] _, Dom.messageEvent => unit) => unit = | ||
"addEventListener"; | ||
|
||
[@mel.send.pipe: t] | ||
external removeMessageErrorEventListener: | ||
([@mel.as "message"] _, Dom.messageEvent => unit) => unit = | ||
"removeEventListener"; | ||
|
||
[@mel.set] | ||
external setOnError: (t, Dom.errorEvent => unit) => unit = "onerror"; | ||
[@mel.set] | ||
external setOnMessage: (t, Dom.messageEvent => unit) => unit = "onmessage"; | ||
[@mel.set] | ||
external setOnMessageError: (t, Dom.messageEvent => unit) => unit = | ||
"onmessageerror"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
type t = Dom.workerGlobalScope; | ||
|
||
module Impl = (T: { | ||
type t; | ||
}) => { | ||
[@mel.get] external self: T.t => T.t = "self"; | ||
|
||
[@mel.send.pipe: T.t] | ||
external addErrorEventListener: | ||
([@mel.as "error"] _, Dom.messageEvent => unit) => unit = | ||
"addEventListener"; | ||
|
||
[@mel.send.pipe: T.t] | ||
external removeErrorEventListener: | ||
([@mel.as "error"] _, Dom.messageEvent => unit) => unit = | ||
"removeEventListener"; | ||
|
||
[@mel.send.pipe: T.t] | ||
external addMessageEventListener: | ||
([@mel.as "message"] _, Dom.messageEvent => unit) => unit = | ||
"addEventListener"; | ||
|
||
[@mel.send.pipe: T.t] | ||
external removeMessageEventListener: | ||
([@mel.as "message"] _, Dom.messageEvent => unit) => unit = | ||
"removeEventListener"; | ||
|
||
[@mel.send.pipe: T.t] | ||
external addMessageErrorEventListener: | ||
([@mel.as "messageerror"] _, Dom.messageEvent => unit) => unit = | ||
"addEventListener"; | ||
|
||
[@mel.send.pipe: T.t] | ||
external removeMessageErrorEventListener: | ||
([@mel.as "messageerror"] _, Dom.messageEvent => unit) => unit = | ||
"removeEventListener"; | ||
}; | ||
|
||
include Webapi__Dom__EventTarget.Impl({ | ||
type nonrec t = t; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davesnx Is it better to have a
globalThis
here? LikeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should add globalThis