value property
T
get
value
Gets the current value of the signal.
If read within a reactive context (like an Effect or Computed), it registers that context as an observer/dependency.
Implementation
T get value {
final active = activeConsumer;
if (active != null) {
addObserver(active);
if (active is DependencyTracker) {
active.addDependency(this);
}
}
return _value;
}
set
value
(T newValue)
Sets a new value for the signal.
If the new value is different from the current value (using standard != equality),
updates the stored value and notifies all observers. The notification phase is batched
to prevent glitches (inconsistent temporary states).
Implementation
set value(T newValue) {
if (_value != newValue) {
final oldValue = _value;
_value = newValue;
signalObserver?.onSignalChanged(this, oldValue, newValue);
for (final listener in List.of(_changeListeners)) {
listener(oldValue, newValue);
}
startBatch();
try {
notifyObservers();
} finally {
endBatch();
}
}
}