package fmlib_browser
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=650393b6315075780d51cc698e2ee19bc359f114fc39365fbe137b24f663189e
doc/fmlib_browser/Fmlib_browser/index.html
Module Fmlib_browserSource
Web Applications Running in the Browser
This library helps to write web applications which run in the browser. See some simple live examples and their source code.
For a step by step introduction see "Introduction to Web Applications".
Utilities
A file handle that represents a user-selected file in the local filesystem. See Command.select_file and Command.select_files on how to obtain file handles.
Event flags to stop propagation and prevent default action.
Navigation
Encode and Decode Javascript Values
Http
Virtual Dom
Commands and Subscriptions
Subscriptions to global events.
Debugging
debug str Log str to the console as a side effect.
debug_value v a Log the javascript value v to the console as a side effect.
Sandbox Applications
A sandbox application has only limited user interactions. A sandbox application cannot execute commands. It can only get messages from user interactions like mouse clicks, keyboard strokes on elements in focus etc.
The dom of a sandbox application is put directly under the body of the html page i.e. it occupies the whole browser window.
sandbox state view update
A sandbox application is started with the command
let _ = sandbox state view updateand it needs only a very simple html file of the form
<!-- file: index.html -->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="webapp.js">
</script>
</head>
<body>
</body>
</html>The application is started on the onload event of the browser window.
val sandbox_plus :
'state ->
('state -> 'msg Html.t) ->
('state -> 'msg Subscription.t) ->
('state -> 'msg -> 'state) ->
unitsandbox_plus state view subs update
A sandbox_plus application is like a sandbox application. In addition it can subscribe to events.
Full Web Application
A full web application has full user interaction, can execute arbitrary commands and subscribe to all possible global events. It allows controlling the browser's title bar (through the return value of the update function) and the browser's address bar (see module Navigation for more details).
val application :
string ->
(Url.t -> 'msg Navigation.key -> ('state * 'msg Command.t) Decoder.t) ->
('state -> 'msg Html.t * string) ->
('state -> 'msg Subscription.t) ->
('state -> 'msg -> 'state * 'msg Command.t) ->
(Navigation.url_request -> 'msg) ->
(Url.t -> 'msg) ->
unitapplication my_app init view subs update on_url_request on_url_change
Browser application named my_app on the javascript side. The application creates the global object named my_app which contains the two functions init and post.
The application is started on the javascript side with
my_app.init ({
data: <initialisation object>,
onMessage: <function to receive messages on the javascript side from
the application>
})The javascript code can post messages to the application by
my_app.post (message)
Basic Web Application
val basic_application :
'state ->
'msg Command.t ->
('state -> 'msg Html.t * string) ->
('state -> 'msg Subscription.t) ->
('state -> 'msg -> 'state * 'msg Command.t) ->
unitbasic_application state command view subs update
A basic_application is like an application with the following differences:
Element Application
An element application is like application above with the difference that the dom is inserted directly under a certain element of the dom tree. The web application generated by the library does not touch the dom outside the user chosen element.
Purpose of the element application: Use an already written webapplication in javascript and add certain functions written in ocaml by using this library.
The element application offers a smooth path to start using the library without rewriting an already existing application from scratch.
The javascript part and the ocaml part can communicate via message passing i.e. the javascript part can post a javascript object to ocaml (see Subscription.on_message) and the ocaml part can send javascript objects (see Value and Task.send_to_javascript).
val element :
string ->
('state * 'msg Command.t) Decoder.t ->
('state -> 'msg Html.t) ->
('state -> 'msg Subscription.t) ->
('state -> 'msg -> 'state * 'msg Command.t) ->
unitelement my_app init view subs update
Browser application named my_app on the javascript side. The application creates the global object named my_app which contains the two functions init and post.
The application is started on the javascript side with
my_app.init ({
data: <initialisation object>,
element_id: <id of the element under which the application works>,
onMessage: <function to receive messages on the javascript side from
the application>
})The javascript code can post messages to the application by
my_app.post (message)