package bonsai

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module type S = sig ... end
type ('input, 'state) t = private {
  1. view : Virtual_dom.Vdom.Node.t;
    (*

    The view of the widget

    *)
  2. modify : ('input -> 'state -> unit) -> unit Bonsai.For_open.Effect.t;
    (*

    A callback for modifying the widget. The most recent inputs and the current state of the widgets are provided.

    *)
  3. read : 'a. ('input -> 'state -> 'a) -> 'a list Bonsai.For_open.Effect.t;
    (*

    read lets you look at the most recent input and current state of any instances of the widget.

    *)
}
val component : ?vdom_for_testing:('input -> Virtual_dom.Vdom.Node.t) -> (module S with type input = 'input and type state = 'state) -> 'input Bonsai.For_open.Value.t -> ('input, 'state) t Bonsai.For_open.Computation.t

A component that makes it easy to build low-level components that make direct modifications to the DOM. Because this component returns a Vdom.Node.t and that vdom node can be placed in multiple locations in the vdom, this component actually tracks a _set of instances_ of this widget. This is why the read function produces a list of read values.

module Low_level : sig ... end

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.

OCaml

Innovation. Community. Security.