package virtual_dom

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
include module type of struct include Ui_effect end
module type Handler = Ui_effect.Handler
type 'a t = 'a Ui_effect.t = ..

'a Effect.t represents some computation of type 'a that can be performed outside of the typical computational/incremental structure of a Bonsai program . Examples of this computation might be:

  • Calling an RPC and getting the result back
  • Running expensive computation on a web-worker thread
  • Requesting some information from the imperative "Start.Handle"-holding code

If you have a value of type 'a Effect.t, you can schedule it to be run by calling inject and providing a function that will be called when the callback completes.

type t +=
  1. | Ignore : Base.unit t
  2. | Many : Base.unit t Base.list -> Base.unit t
include Base.Monad.S with type 'a t := 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
module Monad_infix = Ui_effect.Monad_infix
val bind : 'a t -> f:('a -> 'b t) -> 'b t
val return : 'a -> 'a t
val map : 'a t -> f:('a -> 'b) -> 'b t
val join : 'a t t -> 'a t
val ignore_m : 'a t -> unit t
val all : 'a t list -> 'a list t
val all_unit : unit t list -> unit t
module Let_syntax = Ui_effect.Let_syntax
val never : 'a t

An effect that never completes

val lazy_ : 'a t Base.Lazy.t -> 'a t

If creating an effect could be expensive, you can wrap its construction in a lazy and pass it to this function so that its construction will be deferred until it's about to be evaluated.

val print_s : Base.Sexp.t -> Base.unit t

Prints the sexp when scheduled.

val of_sync_fun : ('query -> 'result) -> 'query -> 'result t

of_sync_fun is similar to of_deferred_fun but with a synchronous function instead of a deferred one. This can be used for functions that are synchronous but side-effecting, or as a mock-function in tests that replace the usages of of_deferred_fun in the actual app.

Note that, unlike of_deferred_fun, the function must return immediately, so it's not possible to test the behaviour of tour app between calling the function and the effect becoming 'determined'. If you need to do this, see of_svar and of_query_response_tracker below.

val of_thunk : (Base.unit -> 'result) -> 'result t

Like of_sync_fun but with a pre-applied unit query. Side-effects in the function will be run every time that the resulting effect is scheduled

module Define = Ui_effect.Define
module Define1 = Ui_effect.Define1
module Private = Ui_effect.Private
module For_testing = Ui_effect.For_testing
module type Visibility_handler = sig ... end
module type S = sig ... end
type t +=
  1. | Viewport_changed
    (*

    Viewport_changed events are delivered to all visibility handlers

    *)
  2. | Stop_propagation
    (*

    Stop_propagation prevents the underlying DOM event from propagating up to the parent elements

    *)
  3. | Stop_immediate_propagation
    (*

    Stop_immediate_propagation causes sequence_as_sibling to ignore next sequenced event.

    *)
  4. | Prevent_default
    (*

    Prevent_default prevents the default browser action from occurring as a result of this event

    *)
val sequence_as_sibling : unit t -> unless_stopped:(unit -> unit t) -> unit t

Sequences two events, but only if the first is neither Stop_immediate_propagation nor a Many which contains Stop_immediate_propagation. Use this instead of Many if combining events that are associated with the same source; for example, the motivation for this function is for merging Inputs of hooks.

The second argument is a function that takes unit not because it is expected to be impure, but because often it is computed via some arbitrary handler function. Using hooks as an example, often the input to a hook has type 'a -> Effect.t. To merge inputs f and g, you might write

fun x -> sequence_as_sibling (f x) (g x)

but this might unnecessarily call g if f returns something with Stop_immediate_propagation. Instead, using this API, you must write

fun x -> sequence_as_sibling (f x) (fun () -> (g x))
module Define_visibility (VH : Visibility_handler) : sig ... end

For registering a handler for Viewport_changed events. Note that if this functor is called multiple times, each handler will see all of the events.

module Expert : sig ... end
OCaml

Innovation. Community. Security.