package fmlib_browser

  1. Overview
  2. Docs

Tasks to be performed within Commands

Error types

type empty =
  1. | []
type http_error = [
  1. | `Http_status of int
    (*
    • 0: no internet, server not found, timeout, ...
    • 401: bad request
    • 403: forbidden
    • 404: page not found
    • ...
    *)
  2. | `Http_no_json
    (*

    Resource is not a valid json file

    *)
  3. | `Http_decode
    (*

    Resource is a valid json file, but the decoder could not decode the corresponding javascript object.

    *)
]
type not_found = [
  1. | `Not_found
]

Basic type and functions

type ('a, +'e) t

Task succeeding with a value of type 'a or failing with an error object of type 'e

val succeed : 'a -> ('a, 'e) t
val return : 'a -> ('a, 'e) t
val fail : 'e -> ('a, 'e) t
val result : ('a, 'e) Stdlib.result -> ('a, 'e) t
val (>>=) : ('a, 'e) t -> ('a -> ('b, 'e) t) -> ('b, 'e) t
val let* : ('a, 'e) t -> ('a -> ('b, 'e) t) -> ('b, 'e) t
val map : ('a -> 'b) -> ('a, 'e) t -> ('b, 'e) t

Write to the console

val log_string : string -> (unit, 'e) t

log_string str Write str to the console.

val log_value : Value.t -> (unit, 'e) t

log_value v Write the javascript object v to the console.

Send messages to the javascript world

val send_to_javascript : Value.t -> (unit, 'e) t

send_to_javascript value Send the javascript object value to the surrounding javascript world.

Focus and blur elements

val focus : string -> (unit, not_found) t

focus id Put the dom element with id into focus.

val blur : string -> (unit, not_found) t

blur id Unfocus the dom element with id.

Defer tasks a certain time

val sleep : int -> 'a -> ('a, 'e) t

sleep millis a Sleep for millis milliseconds and then return a.

Examples:

let* _ = sleep 1000 () in       (* sleep 1000 milliseconds *)
task                            (* and then execute [task] *)

let* a = task1 >>= sleep 1000   (* excute [task1] and return result
                                   [a] after 1000 milliseconds *)
in
task2 a                         (* then execute [task2 a] *)
val next_tick : 'a -> ('a, 'e) t

next_tick a Return a in the next tick of the event loop.

Example: Execute task in the next round of the event loop.

let* _ = next_tick () in
task

Get time and time zone

val now : (Time.t, 'e) t

Get the current time.

val time_zone : (Time.Zone.t, 'e) t

Get the current time zone.

Generate random values

val random : 'a Random.t -> ('a, 'e) t

random ran Execute the random generator rand and return the generated random value.

Make http requests

val http_text : string -> string -> (string * string) list -> string -> (string, http_error) t

http_text method url headers body

Make a http method request to url with headers and body. Expect the response as a string.

Method is one of GET, POST, DELETE, ... .

Then headers and the body can be empty.

val http_json : string -> string -> (string * string) list -> string -> 'a Decoder.t -> ('a, http_error) t
OCaml

Innovation. Community. Security.