Parameter M.1-Component
module Input : sig ... endA 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__.Bonsai_intf.ModelA 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 inInput.t.
module Action : Bonsai__.Bonsai_intf.ActionComponents can change their own
Model.tby issuing "actions" that perform the state transition. If you think of the state machine as having state-nodes of typeModel.t, then the arrows between those nodes would be of typeAction.t.
module Result : sig ... endWhile 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.tWhen an action is raised by this component (via an Event.t), Bonsai will eventually pass that action back to that component's
apply_actionfunction. This function is responsible for looking at the model and the incoming action and producing a new model.apply_actionis a transformation from a model and an action into a new model. During the transformation, the component can also emit more actions viaschedule_eventor use Async to arrange forschedule_eventto be called later.
val compute : inject:(Action.t -> Event.t) -> Input.t -> Model.t -> Result.tcomputeis 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.tto a globalEvent.twhich 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.