Documentation
lwt_react lib
Lwt_react
. E
Module
include module type of React .E
type 'a t = 'a React .event
val never : 'a React .event
val create : unit -> 'a React .event * (?step :React .step -> 'a -> unit)
val retain : 'a React .event -> (unit -> unit) -> [ `R of unit -> unit ]
val stop : ?strong :bool -> 'a React .event -> unit
val equal : 'a React .event -> 'a React .event -> bool
val trace :
?iff :bool React .signal ->
('a -> unit) ->
'a React .event ->
'a React .event
val once : 'a React .event -> 'a React .event
val drop_once : 'a React .event -> 'a React .event
val app : ('a -> 'b ) React .event -> 'a React .event -> 'b React .event
val map : ('a -> 'b ) -> 'a React .event -> 'b React .event
val stamp : 'b React .event -> 'a -> 'a React .event
val filter : ('a -> bool) -> 'a React .event -> 'a React .event
val fmap : ('a -> 'b option ) -> 'a React .event -> 'b React .event
val diff : ('a -> 'a -> 'b ) -> 'a React .event -> 'b React .event
val changes : ?eq :('a -> 'a -> bool) -> 'a React .event -> 'a React .event
val on : bool React .signal -> 'a React .event -> 'a React .event
val when_ : bool React .signal -> 'a React .event -> 'a React .event
val dismiss : 'b React .event -> 'a React .event -> 'a React .event
val until : 'a React .event -> 'b React .event -> 'b React .event
val accum : ('a -> 'a ) React .event -> 'a -> 'a React .event
val fold : ('a -> 'b -> 'a ) -> 'a -> 'b React .event -> 'a React .event
val select : 'a React .event list -> 'a React .event
val merge : ('a -> 'b -> 'a ) -> 'a -> 'b React .event list -> 'a React .event
val switch : 'a React .event -> 'a React .event React .event -> 'a React .event
val fix : ('a React .event -> 'a React .event * 'b ) -> 'b
val l1 : ('a -> 'b ) -> 'a React .event -> 'b React .event
val l2 : ('a -> 'b -> 'c ) -> 'a React .event -> 'b React .event -> 'c React .event
val l3 :
('a -> 'b -> 'c -> 'd ) ->
'a React .event ->
'b React .event ->
'c React .event ->
'd React .event
val l4 :
('a -> 'b -> 'c -> 'd -> 'e ) ->
'a React .event ->
'b React .event ->
'c React .event ->
'd React .event ->
'e React .event
val l5 :
('a -> 'b -> 'c -> 'd -> 'e -> 'f ) ->
'a React .event ->
'b React .event ->
'c React .event ->
'd React .event ->
'e React .event ->
'f React .event
val l6 :
('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g ) ->
'a React .event ->
'b React .event ->
'c React .event ->
'd React .event ->
'e React .event ->
'f React .event ->
'g React .event
Lwt-specific utilitiesval with_finaliser : (unit -> unit) -> 'a event -> 'a event
with_finaliser f e
returns an event e'
which behave as e
, except that f
is called when e'
is garbage collected.
next e
returns the next occurrence of e
.
Avoid trying to create an "asynchronous loop" by calling next e
again in a callback attached to the promise returned by next e
:
The callback is called within the React update step, so calling next e
within it will return a promise that is fulfilled with the same value as the current occurrence. If you instead arrange for the React update step to end (for example, by calling Lwt.pause ()
within the callback), multiple React update steps may occur before the callback calls next e
again, so some occurrences can be effectively "lost." To robustly asynchronously process occurrences of e
in a loop, use to_stream e
, and repeatedly call Lwt_stream.next
on the resulting stream.
limit f e
limits the rate of e
with f
.
For example, to limit the rate of an event to 1 per second you can use: limit (fun () -> Lwt_unix.sleep 1.0) event
.
from f
creates an event which occurs each time f ()
returns a value. If f
raises an exception, the event is just stopped.
Creates a stream holding all values occurring on the given event
of_stream stream
creates an event which occurs each time a value is available on the stream.
If updating the event causes an exception at any point during the update step, the excpetion is passed to !
Lwt.async_exception_hook
, which terminates the process by default.
delay promise
is an event which does not occur until promise
resolves. Then it behaves as the event returned by promise
.
val keep : 'a event -> unit
keep e
keeps a reference to e
so it will never be garbage collected.
The following functions behave as their React
counterpart, except that they take functions that may yield.
As usual the _s
suffix is used when calls are serialized, and the _p
suffix is used when they are not.
Note that *_p
functions may not preserve event order.