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.Tmodule Incr : Incremental.Stype 'custom mismatch_behavior=[|`Ignore|`Raise|`Warn|`Custom of 'custom]Default is
`Ignore.
type ('extra, 'new_model) on_action_mismatch= ('extra -> 'new_model) mismatch_behaviortype ('input, 'model, 'result) tThe component type (
('model, 'result) Bonsai.t) can be thought of as a function from'modelto'result, but where the'resultcan schedule events of the component's "action type". These actions are used to produce a new'modelwhich in turn causes the'resultto be recomputed. Instances of the'resulttype can contain callbacks which schedule actions when interacted with by user (via button click, text input, etc). These actions are handled by the component'sapply_actionfunction, which yields a new model to be displayed.
type ('input, 'model, 'result) nonexpert_t:= ('input, 'model, 'result) t
Component Constructors
val const : 'result -> (_, _, 'result) tReturns a component with no action or model, only a constant result.
val pure : f:('input -> 'result) -> ('input, _, 'result) tA pure function with no model from 'input to 'result
val pure_from_model : f:('model -> 'result) -> (_, 'model, 'result) tLike
pure, but gets the input from the'model.
val compose : ('i1, 'model, 'r1) t -> ('r1, 'model, 'r2) t -> ('i1, 'model, 'r2) tcompose a bjoinsaandbtogether such that the result ofais used as the input ofb.
module Infix : sig ... endFor 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
val return : 'a -> ('a, _, _) tval map : ('a, 'd, 'e) t -> f:('a -> 'b) -> ('b, 'd, 'e) tval 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
val apply : ('a -> 'b, 'd, 'e) t -> ('a, 'd, 'e) t -> ('b, 'd, 'e) tval map2 : ('a, 'd, 'e) t -> ('b, 'd, 'e) t -> f:('a -> 'b -> 'c) -> ('c, 'd, 'e) tval map3 : ('a, 'd, 'e) t -> ('b, 'd, 'e) t -> ('c, 'd, 'e) t -> f:('a -> 'b -> 'c -> 'result) -> ('result, 'd, 'e) tval all : ('a, 'd, 'e) t list -> ('a list, 'd, 'e) tval 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) tval map_input : ('i2, 'model, 'result) t -> f:('i1 -> 'i2) -> ('i1, 'model, 'result) tTransforms the input of a component. The signature of
fis reversed from most other map functions.
include Core_kernel.Applicative.Let_syntax3 with type ('r, 'i, 'm) t := ('i, 'm, 'r) t
module Open_on_rhs_intf : sig ... endmodule Let_syntax : sig ... endmodule Let_syntax : sig ... endmodule type S = sig ... endMany 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)
val of_module : ('input, 'model, 'action, 'result) component_s -> ('input, 'model, 'result) tCreates a component from a
Component.Sfirst class module.
module Incremental : sig ... endmodule Expert : sig ... endCombinators
module Project : sig ... endmodule Map : sig ... endmodule Option : sig ... endmodule Either : sig ... endmodule List_deprecated : sig ... end