package bonsai

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

All the functions in this module incorporate the concept of "edge-triggering", which is the terminology that we use to describe actions that occur when a value changes.

val on_change : Core.Source_code_position.t -> (module Model with type t = 'a) -> 'a Value.t -> callback:('a -> unit Effect.t) Value.t -> unit Computation.t

When given a value and a callback, on_change and on_change' will watch the input variable and call the callback whenever the value changes.

callback is also called when the component is initialized, passing in the first 'a value that gets witnessed.

val on_change' : Core.Source_code_position.t -> (module Model with type t = 'a) -> 'a Value.t -> callback:('a option -> 'a -> unit Effect.t) Value.t -> unit Computation.t

The same as on_change, but the callback function gets access to the previous value that was witnessed.

val lifecycle : ?on_activate:unit Effect.t Value.t -> ?on_deactivate:unit Effect.t Value.t -> ?after_display:unit Effect.t Value.t -> unit -> unit Computation.t

lifecycle is a way to detect when a computation becomes active, inactive, or an event is triggered after every rendering (roughly 60x / second). By depending on this function (with let%sub), you can install events that are scheduled on either case.

When used, the events are scheduled in this order:

  • All deactivations
  • All activations
  • All "after-display"s

and an "after-display" won't occur before an activation, or after a deactivation for a given computation.

val lifecycle' : ?on_activate:unit Effect.t option Value.t -> ?on_deactivate:unit Effect.t option Value.t -> ?after_display:unit Effect.t option Value.t -> unit -> unit Computation.t

Like lifecycle, but the events are optional values. If the event value is None when the action occurs, nothing will happen

val after_display : unit Effect.t Value.t -> unit Computation.t

after_display and after_display' are lower-level functions that can be used to register an event to occur once-per-frame (after each render).

val after_display' : unit Effect.t option Value.t -> unit Computation.t
module Poll : sig ... end
OCaml

Innovation. Community. Security.