package bonsai

  1. Overview
  2. Docs
A library for building dynamic webapps, using Js_of_ocaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.17.0.tar.gz
sha256=c78c4476ee6b856846e2d0941e5965009d5e1b853e564b2b1bee61202f0b1ebb

doc/bonsai.web_ui_widget/Bonsai_web_ui_widget/Low_level/index.html

Module Bonsai_web_ui_widget.Low_levelSource

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.

Sourcemodule Id : Core.T
Sourcetype 's t = {
  1. unsafe_init : 's -> Id.t;
  2. unsafe_destroy : Id.t -> unit;
  3. modify : ('s -> unit) -> unit Bonsai.For_open.Effect.t;
  4. read : 'a. ('s -> 'a) -> 'a list Bonsai.For_open.Effect.t;
}
Sourceval component : unit -> 's t Bonsai.For_open.Computation.t