Signal
Signal
is reactive state that encapsulate a value
changing over time. When the value
of a signal changes, it automatically notifies its observers.
Syntax
Signal
accepts this property:
initialValue
: Initial value ofT
type that the it will hold.
Properties & Methods
Signal
provides the following properties and methods:
value
: A getter/setter that allows to read and write its state.
-
Methods inherited from
RtState
(Learn more here):-
update
: A method to notify changes after run a set of instructions. -
refresh
: A method to force to notify changes. - *
bind
: A method to bind an instance to it. - *
unbind
: A method to unbind an instance to it. - *
dispose
: A method to remove all listeners and free resources.
-
Usage
Declaration
Signal
can be initialized using the constructor class:
Reading and writing the value
Signal
has a value
property that allows to read and write its state:
or also can use the callable function:
or simply use .toString()
implicit to get its value
as String:
Updating the value
Use update
method to notify changes after run a set of instructions:
Use refresh
method to force to notify changes.
Listening to changes
When value
has changed, the Signal
will emit the following events(learn about it here):
Lifecycle.willUpdate
event is triggered before thevalue
change orupdate
,refresh
methods have been invoked.Lifecycle.didUpdate
event is triggered after thevalue
change orupdate
,refresh
methods have been invoked.
Example of listening to changes: