package bonsai
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=1d68aab713659951eba5b85f21d6f9382e0efa8579a02c3be65d9071c6e86303
doc/bonsai.web_ui_widget/Bonsai_web_ui_widget/Low_level/index.html
Module Bonsai_web_ui_widget.Low_level
Source
A mutable-state tracker is meant to be used in concert with Vdom.Node.widget
or Vdom.Attr.create_hook
. Because a widget and hook can exist in multiple places in the dom at the same time, this state-tracker actually tracks a collection of states, which is why read
returns a list, and the callback you pass to modify
can get called multiple times per invocation.
unsafe_init
should be called inside the widget or hooks's init
function and is passed some subset of the widget's state. Then, you must store the returned Id.t in the widget's state. If unsafe_init
is called, then you _must_ call unsafe_destroy
with the returned ID or you risk leaking memory, and making the output of calls to read
return stale data.
unsafe_destroy
should be called inside the widget or hook's destroy
function, and must be passed the same id
that was returned from the corresponding create
.
modify
can be invoked to run some mutating function on the widget's state. It is legal to use this function anywhere that an Effect can be scheduled.
read
provides access to the states of each instance managed by this mutable-state-tracker. You can use this function anywhere that an Effect can be scheduled.
type 's t = {
unsafe_init : 's -> Id.t;
unsafe_destroy : Id.t -> unit;
modify : ('s -> unit) -> unit Bonsai.For_open.Effect.t;
read : 'a. ('s -> 'a) -> 'a list Bonsai.For_open.Effect.t;
}