bonsai
A library for building dynamic webapps, using Js_of_ocaml
1024" x-on:close-sidebar="sidebar=window.innerWidth > 1024 && true">
package bonsai
-
bonsai
-
-
bonsai.bench
-
bonsai.example_chat_open_source_native
-
bonsai.example_chat_open_source_native_common
-
-
bonsai.extra
-
-
bonsai.focus_ring
-
bonsai.protocol
-
bonsai.tailwind_colors
-
bonsai.test
-
bonsai.test.dot
-
bonsai.web_test
-
bonsai.web_ui_common_components
-
bonsai.web_ui_drag_and_drop
-
bonsai.web_ui_element_size_hooks
-
bonsai.web_ui_file
-
bonsai.web_ui_file_from_web_file
-
bonsai.web_ui_form
-
-
bonsai.web_ui_freeform_multiselect
-
bonsai.web_ui_multi_select
-
-
bonsai.web_ui_query_box
-
bonsai.web_ui_reorderable_list
-
bonsai.web_ui_typeahead
Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
Library bonsai.web
val create :
(module Core.Sexpable with type t = 'a) ->
[ `Local_storage | `Session_storage ] ->
unique_id:string ->
default:'a ->
'a t
A Persistent_var.t is similar to Bonsai.Var.t, but the contents of the var are persisted into either local storage or session storage.
Creating a persistent var requires that the type contained inside the var to be sexpable, so a first class module for the type should be passed in.
You have a choice between Local Storage and Session Storage for actually persisting things; The docs for which can be found here:
- https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
- https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
A unique_id
is required for the storage. This value needs to be unique per application.
Finally, a fallback is required for when the value can't be found, or it can't be deserialized.
val update : 'a t -> f:( 'a -> 'a ) -> unit
val set : 'a t -> 'a -> unit
val get : 'a t -> 'a
val value : 'a t -> 'a Bonsai.Value.t
val clear_persistence : 'a t -> unit
This will remove the value from localstorage or sessionstorage. (calling set
or update
afterwards will still store the value back again.)
ON THIS PAGE
No table of contents