Module Bonsai.Make

Bonsai can be used with any Incremental-style UI framework. The parameters for the Bonsai component functor are an instance of Incremental (used to re-evaluate the UI only when the UI model has changed) and an opaque Event.t type (which is used to schedule actions).

The recommended use of this functor is to bind the name Bonsai to its invocation. For example, Bonsai_web's import.ml has:

module Incr = Incr_dom.Incr
module Vdom = Virtual_dom.Vdom
module Bonsai = Bonsai.Make (Incr) (Vdom.Event)

Bonsai_web re-exports the contents of its Import module, which allows users to refer to the module Bonsai to construct components.

Parameters

Signature

module Event : Core_kernel.T
module Incr : Incremental.S
type 'custom mismatch_behavior = [
| `Ignore
| `Raise
| `Warn
| `Custom of 'custom
]

Default is `Ignore.

type ('extra, 'new_model) on_action_mismatch = ('extra -> 'new_model) mismatch_behavior
type ('input, 'model, 'result) t

The component type (('model, 'result) Bonsai.t) can be thought of as a function from 'model to 'result, but where the 'result can schedule events of the component's "action type". These actions are used to produce a new 'model which in turn causes the 'result to be recomputed. Instances of the 'result type can contain callbacks which schedule actions when interacted with by user (via button click, text input, etc). These actions are handled by the component's apply_action function, which yields a new model to be displayed.

type ('input, 'model, 'result) nonexpert_t := ('input'model'result) t

Component Constructors

val const : 'result -> (__'result) t

Returns a component with no action or model, only a constant result.

val pure : f:('input -> 'result) -> ('input_'result) t

A pure function with no model from 'input to 'result

val pure_from_model : f:('model -> 'result) -> (_'model'result) t

Like pure, but gets the input from the 'model.

val compose : ('i1'model'r1) t -> ('r1'model'r2) t -> ('i1'model'r2) t

compose a b joins a and b together such that the result of a is used as the input of b.

module Infix : sig ... end

For composing components which share the same model. For example, applying an action in one component changes the shared model, which is reflected in the results of the other component.

include Core_kernel.Applicative.S3 with type ('r, 'i, 'm) t := ('i'm'r) t
include Base__.Applicative_intf.For_let_syntax3
type ('a, 'd, 'e) t
val return : 'a -> ('a__) t
val map : ('a'd'e) t -> f:('a -> 'b) -> ('b'd'e) t
val both : ('a'd'e) t -> ('b'd'e) t -> ('a * 'b'd'e) t
include Base__.Applicative_intf.Applicative_infix3 with type ('a, 'd, 'e) t := ('a'd'e) t
type ('a, 'd, 'e) t
val (<*>) : ('a -> 'b'd'e) t -> ('a'd'e) t -> ('b'd'e) t
val (<*) : ('a'd'e) t -> (unit, 'd'e) t -> ('a'd'e) t
val (*>) : (unit, 'd'e) t -> ('a'd'e) t -> ('a'd'e) t
val (>>|) : ('a'd'e) t -> ('a -> 'b) -> ('b'd'e) t
val apply : ('a -> 'b'd'e) t -> ('a'd'e) t -> ('b'd'e) t
val map2 : ('a'd'e) t -> ('b'd'e) t -> f:('a -> 'b -> 'c) -> ('c'd'e) t
val map3 : ('a'd'e) t -> ('b'd'e) t -> ('c'd'e) t -> f:('a -> 'b -> 'c -> 'result) -> ('result'd'e) t
val all : ('a'd'e) t list -> ('a list'd'e) t
val all_unit : (unit, 'd'e) t list -> (unit, 'd'e) t
module Applicative_infix : Base__.Applicative_intf.Applicative_infix3 with type ('a, 'd, 'e) t := ('a'd'e) t
val map_input : ('i2'model'result) t -> f:('i1 -> 'i2) -> ('i1'model'result) t

Transforms the input of a component. The signature of f is reversed from most other map functions.

include Core_kernel.Applicative.Let_syntax3 with type ('r, 'i, 'm) t := ('i'm'r) t
type ('a, 'd, 'e) t
module Open_on_rhs_intf : sig ... end
module Let_syntax : sig ... end
module Let_syntax : sig ... end
module type S = sig ... end

Many modules have the same shape, they declare the model, action, and result of the component, and then define apply_action and view over those types.

type ('input, 'model, 'action, 'result) component_s = (module S with type Action.t = 'action and type Input.t = 'input and type Model.t = 'model and type Result.t = 'result)
module M : functor (Component : S) -> sig ... end
val of_module : ('input'model'action'result) component_s -> ('input'model'result) t

Creates a component from a Component.S first class module.

module Incremental : sig ... end
module Expert : sig ... end

Combinators

module Project : sig ... end
module Map : sig ... end
module Option : sig ... end
module Either : sig ... end
module List_deprecated : sig ... end