package bonsai
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=24c4c3149280abd639034ce3acf60e475a772202099e965be8bd8902524573ef
doc/bonsai.web/Bonsai_web/Effect/index.html
Module Bonsai_web.Effect
include module type of Virtual_dom.Vdom.Effect
include module type of struct include Ui_effect end
module type Handler = Virtual_dom.Vdom.Effect.Handlertype 'a t = 'a Virtual_dom.Vdom.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.
include Core.Monad.S with type 'a t := 'a t
module Monad_infix = Ui_effect.Monad_infixval return : 'a -> 'a tmodule Let_syntax = Ui_effect.Let_syntaxval never : 'a tAn effect that never completes
val lazy_ : 'a t Core.Lazy.t -> 'a tIf 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 : Core.Sexp.t -> unit tPrints the sexp when scheduled.
val of_sync_fun : ('query -> 'result) -> 'query -> 'result tof_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.
module Define = Ui_effect.Definemodule Define1 = Ui_effect.Define1module Private = Ui_effect.Privatemodule For_testing = Ui_effect.For_testingmodule type Visibility_handler = Virtual_dom.Vdom.Effect.Visibility_handlermodule type S = Virtual_dom.Vdom.Effect.Stype t += | Viewport_changed(*
*)Viewport_changedevents are delivered to all visibility handlers| Stop_propagation(*
*)Stop_propagationprevents the underlying DOM event from propagating up to the parent elements| Stop_immediate_propagation(*
*)Stop_immediate_propagationcausessequence_as_siblingto ignore next sequenced event.| Prevent_default(*
*)Prevent_defaultprevents the default browser action from occurring as a result of this event
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 = Virtual_dom.Vdom.Effect.Define_visibilityFor 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 = Virtual_dom.Vdom.Effect.Expertval of_deferred_fun :
('query -> 'response Async_kernel.Deferred.t) ->
'query ->
'response tof_deferred_fun is a way to convert from a deferred-returning function to an effect-returning function. This function is commonly used to wrap RPC calls. Memory is allocated permanently every time that of_deferred_fun is called, so be sure to re-use the function inside the Staged.t!