bonsai

A library for building dynamic webapps, using Js_of_ocaml
Legend:
Library
Module
Module type
Parameter
Class
Class type
Library bonsai
type ('input, 'result) t = 'input Value.t -> 'result Computation.t
module type Model = sig ... end
module type Action = sig ... end
val const : 'result -> ( _, 'result ) t

const creates a Bonsai component with an unchanging output. It does not have an input, or a model. Constant components are not frequently used, but can be handy when using an API that requires a Bonsai.t, and you want the result to be constant.

This function is approximately the same as Fn.const.

val input : ( 'result, 'result ) t

input is the identity function as a Bonsai component.

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

pure is used to create a Bonsai component that can be implemented as a pure function from 'input to 'result

val compose : ( 'input, 's ) t -> ( 's, 'result ) t -> ( 'input, 'result ) t

compose (and the >>> infix operator) connect the output from one component into the input of another component. This is conceptually similar to function composition: Fn.compose.

val map : ( 'input, 'r1 ) t -> f:( 'r1 -> 'r2 ) -> ( 'input, 'r2 ) t

map (and the >>| infix operator ) transforms the result type of a Bonsai component using the provided function.

val map_input : ( 'i2, 'result ) t -> f:( 'i1 -> 'i2 ) -> ( 'i1, 'result ) t

map_input (and the @>> infix operator) transforms the input type of a Bonsai component using the provided function.

val of_module : (module Bonsai__Import.Component_s with type Action.t = 'action and type Input.t = 'input and type Model.t = 'model and type Result.t = 'result) -> default_model:'model -> ( 'input, 'result ) t

of_module is one of the most commonly used component constructors. The function takes a first-class module of type Component_s, as well as the default model for the component. For more details, please read the docs for Component_s.

val both : ( 'input, 'r1 ) t -> ( 'input, 'r2 ) t -> ( 'input, 'r1 * 'r2 ) t

Given two components that have the same input, both returns a Bonsai component that contains both of their outputs.

val state_machine : (module Model with type t = 'model) -> (module Action with type t = 'action) -> Core.Source_code_position.t -> default_model:'model -> apply_action: ( inject:( 'action -> unit Ui_effect.t ) -> schedule_event:( unit Ui_effect.t -> unit ) -> 'input -> 'model -> 'action -> 'model ) -> ( 'input, 'model * ( 'action -> unit Ui_effect.t ) ) t

state_machine is a function that is used to define a component solely in terms of its apply_action function. The result value of the component is the value of the current model alongside an injection function to transition the state machine

val enum : (module Bonsai__Import.Enum with type t = 'key) -> which:( 'input -> 'key ) -> handle:( 'key -> ( 'input, 'result ) t ) -> ( 'input, 'result ) t

enum is how a Bonsai component can branch on its input and handle different cases with a different Bonsai component.

The which function translates cases from the components input into values of type 'key.

The handle function translates the values returned by which into the component that handles this value.

val if_ : ( 'input -> bool ) -> then_:( 'input, 'result ) t -> else_:( 'input, 'result ) t -> ( 'input, 'result ) t

if_ is a special case of enum for booleans.

module type S = sig ... end
module Map : sig ... end
val arr : ( 'a -> 'b ) -> ( 'a, 'b ) t

arr is the same as pure.

val (>>^) : ( 'a, 'b ) t -> ( 'b -> 'c ) -> ( 'a, 'c ) t

The same as map

val (^>>) : ( 'a, 'b ) t -> ( 'c -> 'a ) -> ( 'c, 'b ) t

The same as map_input

val first : ( 'input, 'result ) t -> ( 'input * 'a, 'result * 'a ) t

first t applies t to the first part of the input.

val second : ( 'input, 'result ) t -> ( 'a * 'input, 'a * 'result ) t

second t applies t to the second part of the input.

val split : ( 'i1, 'r1 ) t -> ( 'i2, 'r2 ) t -> ( 'i1 * 'i2, 'r1 * 'r2 ) t

split t u applies t to the first part of the input and u to the second part.

val extend_first : ( 'input, 'result ) t -> ( 'input, 'result * 'input ) t

extend_first returns the result of a Bonsai component alongside its input.

val extend_second : ( 'input, 'result ) t -> ( 'input, 'input * 'result ) t

extend_second returns the result of a Bonsai component alongside its input.

val fanout : ( 'input, 'r1 ) t -> ( 'input, 'r2 ) t -> ( 'input, 'r1 * 'r2 ) t

fanout t u applies t and u to the same input and returns both results. It's actually just both.

val (***) : ( 'i1, 'r1 ) t -> ( 'i2, 'r2 ) t -> ( 'i1 * 'i2, 'r1 * 'r2 ) t

t *** u = split t u.

val (&&&) : ( 'input, 'r1 ) t -> ( 'input, 'r2 ) t -> ( 'input, 'r1 * 'r2 ) t

t &&& u = fanout t u.

val partial_compose_first : ( 'input, 'shared * 'output1 ) t -> ( 'input * 'shared, 'output2 ) t -> ( 'input, 'output1 * 'output2 ) t

Composes two components where one of the outputs of the first component is one of the inputs to the second.

val pipe : ( 'input, 'r1 ) t -> into:( 'intermediate, 'r2 ) t -> via:( 'input -> 'r1 -> 'intermediate ) -> finalize:( 'input -> 'r1 -> 'r2 -> 'r3 ) -> ( 'input, 'r3 ) t

pipe connects two components, but provides several functions that ease the transference of data between the components, as well as collect the final result.

module With_incr : sig ... end
module Infix : sig ... end
module Let_syntax : sig ... end