package bonsai

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module Incr : Incremental.S
module Event : sig ... end
type on_action_mismatch = [
  1. | `Ignore
  2. | `Raise
  3. | `Warn
]

Default is `Ignore.

type ('input, 'result) t

The component type (('input, '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.

val sexp_of_t : (_, _) t -> Core_kernel.Sexp.t
val input : ('input, 'input) t

A bonsai component that just forwards the input straight through to the result. This is equivalent to Bonsai.pure ~f:Fn.id.

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 compose : ('i1, 'r1) t -> ('r1, 'r2) t -> ('i1, 'r2) t

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

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 (Component : S) : sig ... end
val of_module : ('input, 'model, 'action, 'result) component_s -> default_model:'model -> ('input, 'result) t
module type Enum = sig ... end
val enum : (module Enum with type t = 'key) -> which:('input -> 'key) -> handle:('key -> ('input, 'result) t) -> ('input, 'result) t
val if_ : ('input -> bool) -> then_:('input, 'result) t -> else_:('input, 'result) t -> ('input, 'result) t

if_ is a simple application of enum to (module Bool).

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.S2 with type ('r, 'i) t := ('i, 'r) t
val return : 'a -> ('b, 'a) t
val map : ('e, 'a) t -> f:('a -> 'b) -> ('e, 'b) t
val both : ('e, 'a) t -> ('e, 'b) t -> ('e, 'a * 'b) t
val (<*>) : ('e, 'a -> 'b) t -> ('e, 'a) t -> ('e, 'b) t
val (<*) : ('e, 'a) t -> ('e, unit) t -> ('e, 'a) t
val (*>) : ('e, unit) t -> ('e, 'a) t -> ('e, 'a) t
val (>>|) : ('e, 'a) t -> ('a -> 'b) -> ('e, 'b) t
val apply : ('e, 'a -> 'b) t -> ('e, 'a) t -> ('e, 'b) t
val map2 : ('e, 'a) t -> ('e, 'b) t -> f:('a -> 'b -> 'c) -> ('e, 'c) t
val map3 : ('e, 'a) t -> ('e, 'b) t -> ('e, 'c) t -> f:('a -> 'b -> 'c -> 'd) -> ('e, 'd) t
val all : ('e, 'a) t list -> ('e, 'a list) t
val all_unit : ('e, unit) t list -> ('e, unit) t
module Applicative_infix : sig ... end
val map_input : ('i2, 'result) t -> f:('i1 -> 'i2) -> ('i1, 'result) t

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

module Proc : sig ... end
module Let_syntax : sig ... end

Combinators

val state_machine : (module Bonsai_types.Model with type t = 'model) -> (module Bonsai_types.Action with type t = 'action) -> Core_kernel.Source_code_position.t -> default_model:'model -> apply_action: (inject:('action -> Event.t) -> schedule_event:(Event.t -> unit) -> 'input -> 'model -> 'action -> 'model) -> ('input, 'model * ('action -> Event.t)) t
module Map : sig ... end
module List_deprecated : sig ... end

Projecting over lists in Bonsai is fraught with issues. 1. Incremental can't be optimized for linked-list data structures. 2. Using list-index as the method for routing actions to components is basically never what you actually want, causing mis-delivery of events every time that the list changes.

module Arrow : sig ... end

('i, _, 'r) t is an arrow from 'i to 'r.

module With_incr : sig ... end
OCaml

Innovation. Community. Security.