Skip to content
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: improve API of Js.Global #973

Merged
merged 2 commits into from
Dec 12, 2023
Merged
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
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ Unreleased
pipe-last ([#968](https://github.com/melange-re/melange/pull/968))
- BREAKING(runtime): Remove unnecessary `unit` argument from `Js.Math.atan2`
([#972](https://github.com/melange-re/melange/pull/972))
- BREAKING(runtime): Add labeled arguments to the callbacks in `Js.Global`
([#973](https://github.com/melange-re/melange/pull/973))

2.2.0 2023-12-05
---------------
Expand Down
18 changes: 4 additions & 14 deletions jscomp/runtime/js_global.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type timeoutId
(** Identify timeout started by {! setTimeout} *)

external clearInterval : intervalId -> unit = "clearInterval"

(** Clear an interval started by {! setInterval}

{[
Expand All @@ -55,7 +54,6 @@ let cancel () =
*)

external clearTimeout : timeoutId -> unit = "clearTimeout"

(** Clear a timeout started by {! setTimeout}
{[
(* A simple model of a code monkey's brain *)
Expand All @@ -73,8 +71,7 @@ let procrastinate mins =
@see <https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout> MDN
*)

external setInterval : (unit -> unit) -> int -> intervalId = "setInterval"

external setInterval : f:(unit -> unit) -> int -> intervalId = "setInterval"
(** {i Repeatedly} executes a callback with a specified interval (in milliseconds) between calls

{b Return} an {! intervalId} that can be passed to {! clearInterval} to cancel the timeout
Expand All @@ -94,9 +91,8 @@ let _ =
]}
*)

external setIntervalFloat : (unit -> unit) -> float -> intervalId
external setIntervalFloat : f:(unit -> unit) -> float -> intervalId
= "setInterval"

(** {i Repeatedly} executes a callback with a specified interval (in milliseconds) between calls

{b Return} an {! intervalId} that can be passed to {! clearInterval} to cancel the timeout
Expand All @@ -116,8 +112,7 @@ let _ =
]}
*)

external setTimeout : (unit -> unit) -> int -> timeoutId = "setTimeout"

external setTimeout : f:(unit -> unit) -> int -> timeoutId = "setTimeout"
(** Execute a callback after a specified delay (in milliseconds)

{b returns} a {! timeoutId} that can be passed to {! clearTimeout} to cancel the timeout
Expand All @@ -134,8 +129,7 @@ let _ =
]}
*)

external setTimeoutFloat : (unit -> unit) -> float -> timeoutId = "setTimeout"

external setTimeoutFloat : f:(unit -> unit) -> float -> timeoutId = "setTimeout"
(** Execute a callback after a specified delay (in milliseconds)

{b returns} a {! timeoutId} that can be passed to {! clearTimeout} to cancel the timeout
Expand All @@ -153,28 +147,24 @@ let _ =
*)

external encodeURI : string -> string = "encodeURI"

(** URL-encodes a string.

@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI> MDN
*)

external decodeURI : string -> string = "decodeURI"

(** Decodes a URL-enmcoded string produced by [encodeURI]

@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI> MDN
*)

external encodeURIComponent : string -> string = "encodeURIComponent"

(** URL-encodes a string, including characters with special meaning in a URI.

@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent> MDN
*)

external decodeURIComponent : string -> string = "decodeURIComponent"

(** Decodes a URL-enmcoded string produced by [encodeURIComponent]

@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent> MDN
Expand Down
4 changes: 2 additions & 2 deletions jscomp/test/js_global_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ open Js.Global
let suites = Mt.[

("setTimeout/clearTimeout sanity check", (fun _ ->
let handle = setTimeout (fun () -> ()) 0 in
let handle = setTimeout ~f:(fun () -> ()) 0 in
clearTimeout handle;
Ok true
));

("setInerval/clearInterval sanity check", (fun _ ->
let handle = setInterval (fun () -> ()) 0 in
let handle = setInterval ~f:(fun () -> ()) 0 in
clearInterval handle;
Ok true
));
Expand Down
Loading