value property

  1. @override
T get value
override

The current value.

Reading this inside a TitanComputed or TitanEffect automatically registers a dependency.

Implementation

@override
T get value {
  track();
  return _value;
}
set value (T newValue)

Sets the value. If Conduits are attached, the value is piped through each before being applied. If the final value differs from the current value (per the equality function), dependents and listeners are notified.

Throws ConduitRejectedException if any Conduit rejects the change.

Implementation

set value(T newValue) {
  // Pipe through conduits
  var piped = newValue;
  final conduits = _conduits;
  if (conduits != null) {
    for (final conduit in conduits) {
      piped = conduit.pipe(_value, piped);
    }
  }

  if (_isEqual(_value, piped)) return;

  final oldValue = _value;
  _previousValue = oldValue;
  _value = piped;

  // Notify all observers (skip method call to avoid boxing overhead
  // when no observers are registered — the common production case).
  if (TitanObserver.hasObservers) {
    TitanObserver.notifyStateChanged(
      state: this,
      oldValue: oldValue,
      newValue: piped,
    );
  }

  notifyDependents();

  // Post-change callbacks
  if (conduits != null) {
    for (final conduit in conduits) {
      conduit.onPiped(oldValue, piped);
    }
  }
}