Module Bonsai_web.Effect
include Core_kernel.Monad.S with type 'a t := 'a t
include Base__.Monad_intf.S_without_syntax with type 'a t := 'a t
module Monad_infix : Base__.Monad_intf.Infix with type 'a t := 'a tval return : 'a -> 'a treturn vreturns the (trivial) computation that returns v.
val of_event : Bonsai_web__.Import.Vdom.Event.t -> unit tConverts a
Vdom.Event.tto anEffect.t. This can be useful if you want to use the monadic interface that is available viaEffect.tin order to sequence events.
val of_deferred_fun : ('query -> 'result Async_kernel.Deferred.t) -> ('query -> 'result t) Core_kernel.Staged.tof_deferred_funis 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 permenantly every time thatof_deferred_funis called, so be sure to re-use the function inside the Staged.t!
val of_sync_fun : ('query -> 'result) -> ('query -> 'result t) Core_kernel.Staged.tof_sync_funis similar toof_deferred_funbut 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 ofof_deferred_funin the actual app.
val never : _ tAn effect that never completes
val inject : 'a t -> on_response:('a -> Bonsai_web__.Import.Vdom.Event.t) -> Bonsai_web__.Import.Vdom.Event.tProduces an event which schedules the some computation to be run. When that computation is complete,
on_responseis called with the value.
val inject_ignoring_response : unit t -> Bonsai_web__.Import.Vdom.Event.tWhen the type being computed is unit, you are calling this Effect for side-effects that don't yield a value back.
inject_ignoring_responsefrees you from having to pass anon_responsecallback.
val inject_with_userdata : 'a t -> userdata:'u -> on_response:('a -> 'u -> Bonsai_web__.Import.Vdom.Event.t) -> Bonsai_web__.Import.Vdom.Event.tinject_with_userdatais the same asinject, but you have the option of passing in some extra value which will also be available in theon_responsecallback.
val handle_error : ('ok, 'error) Core_kernel.Result.t t -> f:('error -> Bonsai_web__.Import.Vdom.Event.t) -> 'ok tTransforms a result-returing
Effect.tinto anEffect.tthat doesn't have it's error case, by providing a callback that handles the error condition.