Page
Library
Module
Module type
Parameter
Class
Class type
Source
Fmlib_browser.CommandSourceCommands to be executed.
An elementary command consists of a Task to be executed.
msg t is the type of a command generating an object of type msg to inject it into the update function of the application.
Get the time zone.
focus id
Focus the element id. If the element does not exist, then nothing is done. This command does not return any message.
blur id
Blur the element id. If the element does not exist, then nothing is done. This command does not return any message.
focus_with_info id ok not_found
Focus the element id and return ok. Return not_found, if the element does not exist.
blur_with_info id ok not_found
Blur the element id and return ok. Return not_found, if the element does not exist.
select_file media_types f Show the browser's file selection dialog and produce f file when the user selected a file. The given list of media_types allows restricting what file types are visible in the dialog (users can still select different file types if they want to).
NOTE: This command only works if it is triggered in reaction to a user event, such as a mouse click. This restriction is imposed by browsers for security reasons (websites should not be able to ask for file access without user interaction).
select_files media_types f The same as select_file but allows selecting multiple files at once.
NOTE: This command only works if it is triggered in reaction to a user event, such as a mouse click. This restriction is imposed by browsers for security reasons (websites should not be able to ask for file access without user interaction).
file_text file f
Read the contents of file into a string result and produce the message f result when reading has finished. Reading can fail, e.g. in case of missing filesystem permissions.
push_url navigation_key url
Set the browser address bar to url and add an entry to the browser history. This requires a navigation_key which is only available in full web applications. See Navigation.key for details.
NOTE: For security reasons browsers don't allow setting an invalid URL or a URL with a different origin (protocol, hostname and port) than the current URL. Browsers may also enforce a rate limit for changing the URL. This means that if url is not a valid URL of the same origin or if we try to change the URL too frequently, an exception is thrown.
replace_url navigation_key url
Like push_url, but do not add a new entry to the browser history.
This is useful for changing the query part of the URL according to user input, e.g. ?search=hats. If push_url was used in this case, navigating back would undo a single keystroke whereas users would rather expect to go to the previous page.
NOTE: For security reasons browsers don't allow setting an invalid URL or a URL with a different origin (protocol, hostname and port) than the current URL. Browsers may also enforce a rate limit for changing the URL. This means that if url is not a valid URL of the same origin or if we try to change the URL too frequently, an exception is thrown.
back navigation_key count
Navigate back count entries in the browser history. This requires a navigation_key which is only available in full web applications. See Navigation.key for details.
forward navigation_key count
Navigate forward count entries in the browser history. This requires a navigation_key which is only available in full web applications. See Navigation.key for details.
load url
Load the given url. This causes a traditional page load. For navigating to a different page within a single-page application, use push_url instead.
More details on reference nodes see Html.reference.
set_reference name vdom
Display vdom in the reference node name.
If a reference node name does not yet exist, then create a reference node.
val http_request :
string ->
string ->
(string * string) list ->
Http.Body.t ->
'm Http.Expect.t ->
(Http.error -> 'm) ->
'm thttp_request method url headers body expect on_error
Make an http method request to url with headers and body. expect specifies the expected response format and can be used to produce a message. on_error transforms a Http.error into a message.
Examples:
(* Send an empty body and expect a string response *)
let on_success msg = Got_message msg in
let on_error _ = Got_error "Failed to obtain message" in
http_request
"GET"
"/message/123"
[]
Http.Body.empty
(Http.Expect.map on_success Http.Expect.string)
on_error
(* Send file contents as the body and expect a json object with
field "url" *)
let on_success url = Got_file_uploaded url in
let on_error _ = Got_error "file upload failed" in
http_request
"PUT"
"/upload/my_file.txt"
[]
(Http.Body.file file)
(Http.Expect.json Decoder.(map on_success (field "url" string)))
on_errorIf a command wants to execute chains of simple commands before returning a message to the application, then it is necessary to create a task which does the more complex operation and perform the task within a command.
An object of type ('a, 'e) Task.t is a task which in case of success returns a value of type 'a and in case of failure returns a value of type 'e.
An object of type ('a, Task.empty) Task.t is a task which cannot fail.
attempt f task Attempt the possibly failing task and map the result via the function f into a message to send to the application.
perform task Perform the non failing task and send the message generated by the task to the application.
perform task Perform the non failing task and don't send any message to the application.