include module type of React.S
Primitive and basics
type 'a t = 'a React.signalThe type for signals of type 'a.
val const : 'a -> 'a React.signalconst v is always v, [const v]t = v.
val create : ?eq:('a -> 'a -> bool) -> 'a -> 'a React.signal * (?step:React.step -> 'a -> unit)create i is a primitive signal s set to i and a set function. The function set is such that:
set vsets the signal's value tovat the time it is called and triggers an update step.set ~step vsets the signal's value tovat the time it is called and updates it dependencies whenstepis executedset ~step vraisesInvalid_argumentif it was previously called with a step and this step has not executed yet or if the givenstepwas already executed.
Warning. set must not be executed inside an update step.
val value : 'a React.signal -> 'avalue s is s's current value.
Warning. If executed in an update step may return a non up-to-date value or raise Failure if the signal is not yet initialized.
val retain : 'a React.signal -> (unit -> unit) -> [ `R of unit -> unit ]retain s c keeps a reference to the closure c in s and returns the previously retained value. c will never be invoked.
Raises. Invalid_argument on constant signals.
val stop : ?strong:bool -> 'a React.signal -> unitstop s, stops updating s. It conceptually becomes const with the signal's last value and cannot be restarted. Allows to disable effectful signals.
The strong argument should only be used on platforms where weak arrays have a strong semantics (i.e. JavaScript). See details.
Note. If executed in an update step the signal may still update in the step.
val equal : ?eq:('a -> 'a -> bool) -> 'a React.signal -> 'a React.signal -> boolval trace : ?iff:bool t -> ('a -> unit) -> 'a React.signal -> 'a React.signaltrace iff tr s is s except tr is invoked with s's current value and on s changes when iff is true (defaults to S.const true). For all t where [s]t = v and (t = 0 or ([s]t-dt= v' and eq v v' = false)) and [iff]t = true, tr is invoked with v.
From events
val hold : ?eq:('a -> 'a -> bool) -> 'a -> 'a React.event -> 'a React.signalhold i e has the value of e's last occurrence or i if there wasn't any.
- [
hold i e]t= iif [e]<=t= None - [
hold i e]t= vif [e]<=t= Some v
Transforming and filtering
val app : ?eq:('b -> 'b -> bool) -> ('a -> 'b) React.signal -> 'a React.signal -> 'b React.signalapp sf s holds the value of sf applied to the value of s, [app sf s]t = [sf]t [s]t.
val map : ?eq:('b -> 'b -> bool) -> ('a -> 'b) -> 'a React.signal -> 'b React.signalmap f s is s transformed by f, [map f s]t = f [s]t.
val filter : ?eq:('a -> 'a -> bool) -> ('a -> bool) -> 'a -> 'a React.signal -> 'a React.signalfilter f i s is s's values that satisfy p. If a value does not satisfy p it holds the last value that was satisfied or i if there is none.
- [
filter p s]t=[s]t ifp[s]t= true. - [
filter p s]t=[s]t' ifp[s]t= falseand t' is the greatest t' < t withp[s]t'= true. - [
filter p e]t= iotherwise.
val fmap : ?eq:('b -> 'b -> bool) -> ('a -> 'b option) -> 'b -> 'a React.signal -> 'b React.signalfmap fm i s is s filtered and mapped by fm.
- [
fmap fm i s]t=v iffm[s]t= Some v. - [
fmap fm i s]t=[fmap fm i s]t' iffm[s]t= Noneand t' is the greatest t' < t withfm[s]t'<> None. - [
fmap fm i s]t= iotherwise.
val diff : ('a -> 'a -> 'b) -> 'a React.signal -> 'b React.eventdiff f s is an event with occurrences whenever s changes from v' to v and eq v v' is false (eq is the signal's equality function). The value of the occurrence is f v v'.
- [
diff f s]t= Some dif [s]t= vand [s]t-dt= v'andeq v v' = falseandf v v' = d. - [
diff f s]t= Noneotherwise.
val changes : 'a React.signal -> 'a React.eventchanges s is diff (fun v _ -> v) s.
val sample : ('b -> 'a -> 'c) -> 'b React.event -> 'a React.signal -> 'c React.eventsample f e s samples s at e's occurrences.
- [
sample f e s]t= Some (f ev sv)if [e]t= Some evand [s]t= sv. - [
sample e s]t= Noneotherwise.
val on : ?eq:('a -> 'a -> bool) -> bool React.signal -> 'a -> 'a React.signal -> 'a React.signalon c i s is the signal s whenever c is true. When c is false it holds the last value s had when c was the last time true or i if it never was.
- [
on c i s]t=[s]t if [c]t= true - [
on c i s]t=[s]t' if [c]t= falsewhere t' is the greatest t' < t with [c]t'= true. - [
on c i s]t=iotherwise.
val when_ : ?eq:('a -> 'a -> bool) -> bool React.signal -> 'a -> 'a React.signal -> 'a React.signal- deprecated
Use
on.
val dismiss : ?eq:('a -> 'a -> bool) -> 'b React.event -> 'a -> 'a React.signal -> 'a React.signaldismiss c i s is the signal s except changes when c occurs are ignored. If c occurs initially i is used.
- [
dismiss c i s]t=[s]t' where t' is the greatest t' <= t with [c]t'= Noneand [s]t'-dt<>[s]t' - [
dismiss_ c i s]0=vwherev = iif [c]0= Some _andv =[s]0 otherwise.
Accumulating
val accum : ?eq:('a -> 'a -> bool) -> ('a -> 'a) React.event -> 'a -> 'a React.signalaccum e i is S.hold i (E:accum e i).
val fold : ?eq:('a -> 'a -> bool) -> ('a -> 'b -> 'a) -> 'a -> 'b React.event -> 'a React.signalfold f i e is S.hold i (E.fold f i e).
Combining
val merge : ?eq:('a -> 'a -> bool) -> ('a -> 'b -> 'a) -> 'a -> 'b React.signal list -> 'a React.signalmerge f a sl merges the value of every signal in sl using f and the accumulator a.
[merge f a sl]t = List.fold_left f a (List.map []t sl).
val switch : ?eq:('a -> 'a -> bool) -> 'a React.signal React.signal -> 'a React.signalswitch ss is the inner signal of ss.
- [
switch ss]t=[[ss]t]t.
val bind : ?eq:('b -> 'b -> bool) -> 'a React.signal -> ('a -> 'b React.signal) -> 'b React.signalbind s sf is switch (map ~eq:( == ) sf s).
val fix : ?eq:('a -> 'a -> bool) -> 'a -> ('a React.signal -> 'a React.signal * 'b) -> 'bfix i sf allow to refer to the value a signal had an infinitesimal amount of time before.
In fix sf, sf is called with a signal s that represents the signal returned by sf delayed by an infinitesimal amount time. If s', r = sf s then r is returned by fix and s is such that :
- [
s]t=ifor t = 0. - [
s]t=[s']t-dt otherwise.
eq is the equality used by s.
Raises. Invalid_argument if s' is directly a delayed signal (i.e. a signal given to a fixing function).
Note. Regarding values depending on the result r of s', r = sf s the following two cases need to be distinguished :
After
sf sis applied,s'does not depend on a value that is in a step andshas no dependents in a step (e.g in the simple case wherefixis applied outside a step).In that case if the initial value of
s'differs fromi,sand its dependents need to be updated and a special update step will be triggered for this. Values depending on the resultrwill be created only after this special update step has finished (e.g. they won't see theiofsifr = s).- Otherwise, values depending on
rwill be created in the same step assands'(e.g. they will see theiofsifr = s).
Lifting
val l1 : ?eq:('b -> 'b -> bool) -> ('a -> 'b) -> 'a React.signal -> 'b React.signalval l2 : ?eq:('c -> 'c -> bool) -> ('a -> 'b -> 'c) -> 'a React.signal -> 'b React.signal -> 'c React.signalval l3 : ?eq:('d -> 'd -> bool) -> ('a -> 'b -> 'c -> 'd) -> 'a React.signal -> 'b React.signal -> 'c React.signal -> 'd React.signalval l4 : ?eq:('e -> 'e -> bool) -> ('a -> 'b -> 'c -> 'd -> 'e) -> 'a React.signal -> 'b React.signal -> 'c React.signal -> 'd React.signal -> 'e React.signalval l5 : ?eq:('f -> 'f -> bool) -> ('a -> 'b -> 'c -> 'd -> 'e -> 'f) -> 'a React.signal -> 'b React.signal -> 'c React.signal -> 'd React.signal -> 'e React.signal -> 'f React.signalval l6 : ?eq:('g -> 'g -> bool) -> ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g) -> 'a React.signal -> 'b React.signal -> 'c React.signal -> 'd React.signal -> 'e React.signal -> 'f React.signal -> 'g React.signalmodule Bool : sig ... endmodule Int : sig ... endmodule Float : sig ... endmodule Pair : sig ... endmodule Option : sig ... endmodule Compare : sig ... endCombinator specialization
Functor specializing the combinators for the given signal value type
module Special : sig ... endSpecialization for booleans, integers and floats.
Monadic interface
val return : 'a -> 'a signalSame as const.
bind ?eq s f is initially f x where x is the current value of s. Each time s changes to a new value y, bind
signal f is set to f y, until the next change of signal.
Same as bind except that f returns a promise. Calls to f are serialized.
Lwt-specific utilities
with_finaliser f s returns a signal s' which behaves as s, except that f is called when s' is garbage collected.
limit f s limits the rate of s update with f.
For example, to limit it to 1 per second, you can use: limit
(fun () -> Lwt_unix.sleep 1.0) s.
val keep : 'a signal -> unitkeep s keeps a reference to s so it will never be garbage collected.
Threaded versions of React transformation functions
val fmap_s : ?eq:('b -> 'b -> bool) -> ('a -> 'b option Lwt.t) -> 'b -> 'a signal -> 'b signal Lwt.tval merge_s : ?eq:('a -> 'a -> bool) -> ('a -> 'b -> 'a Lwt.t) -> 'a -> 'b signal list -> 'a signal Lwt.tval l2_s : ?eq:('c -> 'c -> bool) -> ('a -> 'b -> 'c Lwt.t) -> 'a signal -> 'b signal -> 'c signal Lwt.tval l3_s : ?eq:('d -> 'd -> bool) -> ('a -> 'b -> 'c -> 'd Lwt.t) -> 'a signal -> 'b signal -> 'c signal -> 'd signal Lwt.tval l4_s : ?eq:('e -> 'e -> bool) -> ('a -> 'b -> 'c -> 'd -> 'e Lwt.t) -> 'a signal -> 'b signal -> 'c signal -> 'd signal -> 'e signal Lwt.tval l5_s : ?eq:('f -> 'f -> bool) -> ('a -> 'b -> 'c -> 'd -> 'e -> 'f Lwt.t) -> 'a signal -> 'b signal -> 'c signal -> 'd signal -> 'e signal -> 'f signal Lwt.t