package bonsai

  1. Overview
  2. Docs
val of_incr : 'result Incr.t -> (_, _, 'result) t

Constructs a bonsai component whose result is always the same as its input Incremental node.

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

Same as Bonsai.pure but allows the user to optimize using Incremental.

val pure_from_model : f:('model Incr.t -> 'result Incr.t) -> (_, 'model, 'result) t

Same as Bonsai.pure_from_model, but allows the user to optimize using Incremental.

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

Transforms the result of a component, exposing the incrementality for optimization purposes.

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

Transforms the input of a component, exposing the incrementality for optimization purposes. The signature of f is reversed from most other map functions.

module Case : sig ... end
val switch : f: (('outer_input, 'outer_model, 'result) Case.case_creator -> 'outer_input Incr.t -> 'outer_model Incr.t -> ('outer_input, 'outer_model, 'result) Case.case Incr.t) -> ('outer_input, 'outer_model, 'result) t

switch is a function designed to be used in conjunction with ppx_pattern_bind in order to provide dynamic switching between components based on a variant.

The f argument takes a case_creator which contains a field named create_case which can be used on the right-hand side of a match to handle that case.

The create_case function takes four arguments

  • The component for that case;
  • The input for that component;
  • The model for that component (either the input or model is typically the pattern variable that was bound in this match-arm);
  • A lifting function that re-wraps the model in a way that promotes changes to the model back to the outer variant model.

Here is an example usage that changes components based on the model. With a small change, the input instead could be used to switch components.

let my_component = switch ~f:(fun { create_case } input model  ->
  let open Incr.Let_syntax in
  match%pattern_bind model with
  | Nullary_variant ->
    create_case
      component_a
      ~case_input:input
      ~case_model:(Incr.return ())
      ~lift:(fun () -> Nullary_variant)
  | Unary_variant submodel ->
    create_case
      component_b
      ~case_input:input
      ~case_model:submodel
      ~lift:(fun submodel -> Unary_variant submodel))
module type S = sig ... end
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) t
OCaml

Innovation. Community. Security.