Module Js.Global

Provide bindings to JS global functions in global namespace

Contains functions available in the global scope (window in a browser context)

type intervalId;

Identify an interval started by setInterval

type timeoutId;

Identify timeout started by setTimeout

let clearInterval: intervalId => unit;

Clear an interval started by setInterval

(* API for a somewhat aggressive snoozing alarm clock *)

let interval = ref Js.Nullable.null

let remind () =
  Js.log "Wake Up!";
  IO.punchSleepyGuy ()

let snooze mins =
  interval := Js.Nullable.return (Js.Global.setInterval remind (mins * 60 * 1000))

let cancel () =
  Js.Nullable.iter !interval (fun[\@bs] intervalId -> Js.Global.clearInterval intervalId)
let clearTimeout: timeoutId => unit;

Clear a timeout started by setTimeout

(* A simple model of a code monkey's brain *)

let timer = ref Js.Nullable.null

let work () =
  IO.closeHackerNewsTab ()

let procrastinate mins =
  Js.Nullable.iter !timer (fun[\@bs] timer -> Js.Global.clearTimeout timer);
  timer := Js.Nullable.return (Js.Global.setTimeout work (mins * 60 * 1000))
let setInterval: (unit => unit) => int => intervalId;

Repeatedly executes a callback with a specified interval (in milliseconds) between calls

Return an intervalId that can be passed to clearInterval to cancel the timeout

let setIntervalFloat: (unit => unit) => float => intervalId;

Repeatedly executes a callback with a specified interval (in milliseconds) between calls

Return an intervalId that can be passed to clearInterval to cancel the timeout

let setTimeout: (unit => unit) => int => timeoutId;

Execute a callback after a specified delay (in milliseconds)

returns a timeoutId that can be passed to clearTimeout to cancel the timeout

let setTimeoutFloat: (unit => unit) => float => timeoutId;

Execute a callback after a specified delay (in milliseconds)

returns a timeoutId that can be passed to clearTimeout to cancel the timeout

let encodeURI: string => string;

URL-encodes a string.

let decodeURI: string => string;

Decodes a URL-enmcoded string produced by encodeURI

let encodeURIComponent: string => string;

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

let decodeURIComponent: string => string;

Decodes a URL-enmcoded string produced by encodeURIComponent