Module Incremental.Var
val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> ('w -> Ppx_sexp_conv_lib.Sexp.t) -> ('a, 'w) t -> Ppx_sexp_conv_lib.Sexp.t
val create : 'w State.t -> ?use_current_scope:bool -> 'a -> ('a, 'w) t
By default, a variable is created in
Scope.top
, on the theory that its value depends on external stimuli (viaVar.set
), not on the current scope. However, in some situations it is useful to supply~use_current_scope:true
to create a variable that is invalidated when the current scope is invalidated, e.g. if one wants to useon_update (watch var) ~f:(function Invalidated -> ... | ...)
to remove the external stimulus that was settingvar
.It is allowed to do
let t = create a
during stabilization; for that stabilization,watch t
will have valuea
.
val set : ('a, _) t -> 'a -> unit
set t a
sets the value oft
toa
. Outside of stabilization, subsequent calls toVar.value t
will seea
, but theset
will not have any effect on incrementals until the next stabilization, at which pointwatch t
will take on whatevervalue t
was at the start of stabilization, causing incremental recomputation as usual.During a stabilization, calling
set
will behave as ifset
was called after stabilization finished: the new value will not be seen (byvalue v
orwatch v
) until after the stabilization finishes.
val watch : ('a, 'w) t -> ('a, 'w) incremental
watch t
returns an incremental that tracks the value oft
. For a givent
, all calls towatch t
return the same incremental.
val value : ('a, _) t -> 'a
value t
returns the value most recentlyset
fort
outside of stabilization.
val latest_value : ('a, _) t -> 'a
latest_value t
returns the value most recentlyset
fort
. It can differ fromvalue t
only during stabilization.
val replace : ('a, _) t -> f:('a -> 'a) -> unit
replace t ~f
=set t (f (latest_value t))