Vdom.EffectSourceinclude module type of struct include Ui_effect end'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:
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 Base.Monad.S with type 'a t := 'a tt >>= 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.
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.
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.
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.
Prints the sexp when scheduled.
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.
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
type t += | Viewport_changedViewport_changed events are delivered to all visibility handlers
| Stop_propagationStop_propagation prevents the underlying DOM event from propagating up to the parent elements
| Stop_immediate_propagationStop_immediate_propagation causes sequence_as_sibling to ignore next sequenced event.
| Prevent_defaultPrevent_default prevents 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))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.