Module Bonsai.Edge

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 : here:lexing_position -> ?sexp_of_model:('a -> Core.Sexp.t) -> trigger:[ `Before_display | `After_display ] -> equal:('a -> 'a -> bool) -> '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.

These functions do not wait for previous calls to callback to complete before calling it again.

val on_change' : here:lexing_position -> ?sexp_of_model:('a -> Core.Sexp.t) -> trigger:[ `Before_display | `After_display ] -> equal:('a -> 'a -> bool) -> '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 : here:lexing_position -> ?on_activate:unit Effect.t Value.t -> ?on_deactivate:unit Effect.t Value.t -> ?before_display: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' : here:lexing_position -> ?on_activate:unit Effect.t option Value.t -> ?on_deactivate:unit Effect.t option Value.t -> ?before_display: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 before_display : here:lexing_position -> unit Effect.t Value.t -> unit Computation.t

before_display and before_display' are lower-level functions that can be used to register an event to occur once-per-frame (before the vdom is mounted)

val before_display' : here:lexing_position -> unit Effect.t option Value.t -> unit Computation.t
val after_display : here:lexing_position -> 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' : here:lexing_position -> unit Effect.t option Value.t -> unit Computation.t
val wait_after_display : here:lexing_position -> unit -> unit Effect.t Computation.t

wait_after_display is an effect that will complete after the next frame.

module Poll : sig ... end