package virtual_dom

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

Module Ui_effectSource

Sourcemodule type Handler = sig ... end
Sourcemodule type S = sig ... end
Sourcetype 'a 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.

Sourcetype 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
Sourceval (>>=) : 'a t -> ('a -> 'b t) -> 'b t

t >>= f returns a computation that sequences the computations represented by two monad elements. The resulting computation first does t to yield a value v, and then runs the computation returned by f v.

Sourceval (>>|) : 'a t -> ('a -> 'b) -> 'b t

t >>| f is t >>= (fun a -> return (f a)).

Sourcemodule Monad_infix : sig ... end
Sourceval bind : 'a t -> f:('a -> 'b t) -> 'b t

bind t ~f = t >>= f

Sourceval return : 'a -> 'a t

return v returns the (trivial) computation that returns v.

Sourceval map : 'a t -> f:('a -> 'b) -> 'b t

map t ~f is t >>| f.

Sourceval join : 'a t t -> 'a t

join t is t >>= (fun t' -> t').

Sourceval ignore_m : 'a t -> unit t

ignore_m t is map t ~f:(fun _ -> ()). ignore_m used to be called ignore, but we decided that was a bad name, because it shadowed the widely used Stdlib.ignore. Some monads still do let ignore = ignore_m for historical reasons.

Sourceval all : 'a t list -> 'a list t
Sourceval all_unit : unit t list -> unit t

Like all, but ensures that every monadic value in the list produces a unit value, all of which are discarded rather than being collected into a list.

Sourcemodule Let_syntax : sig ... end

These are convenient to have in scope when programming with a monad:

Sourceval never : 'a t

An effect that never completes

Sourceval 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.

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

Prints the sexp when scheduled.

Sourceval 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.

Sourcemodule Define (Handler : Handler) : S with type action := Handler.Action.t and type 'a t := 'a t
Sourcemodule Define1 (Handler : sig ... end) : sig ... end
Sourcemodule Expert : sig ... end
Sourcemodule Private : sig ... end
Sourcemodule For_testing : sig ... end
OCaml

Innovation. Community. Security.