package bonsai
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=43f35d648644492d776bf2c7b86c8227e7793615b6a658432e95f8dccd3631f8
md5=b5e743dbfa64d0da5fd660f14cd0b549
doc/bonsai.web/Bonsai_web/Bonsai/M/argument-1-Component/index.html
Parameter M.Component
module Input : sig ... end
A component receives read-only input, either as output from other components or from an external system (e.g. data from a server). The input is frequently dynamic, but may also be constant.
module Model : Bonsai_types.Model
A component's model is a state-machine that the component can read, but also write to. Because both the input and model are readable, it can be hard to decide whether to request some data from the input or the model. It is highly recommended to put just the data that needs mutation in Model.t
, and the rest in Input.t
.
module Action : Bonsai_types.Action
Components can change their own Model.t
by issuing "actions" that perform the state transition. If you think of the state machine as having state-nodes of type Model.t
, then the arrows between those nodes would be of type Action.t
.
module Result : sig ... end
While UI components stereotypically produce some kind of "view", with Bonsai, components are small and easy enough to compose that Bonsai components frequently produce intermediate results which are then wired into other components.
val apply_action :
inject:(Action.t -> Event.t) ->
schedule_event:(Event.t -> unit) ->
Input.t ->
Model.t ->
Action.t ->
Model.t
When an action is raised by this component (via an Event.t), Bonsai will eventually pass that action back to that component's apply_action
function. This function is responsible for looking at the model and the incoming action and producing a new model.
apply_action
is a transformation from a model and an action into a new model. During the transformation, the component can also emit more actions via schedule_event
or use Async to arrange for schedule_event
to be called later.
compute
is a function from input and model to the component's result. In a component that produces a view, this function could be thought of as the "view computation function".
This function is also given an "inject" function which converts this component's Action.t
to a global Event.t
which can be given to Bonsai to schedule. Frequently, this Event.t is embedded within the result as a handler for some kind of user input.