ComputedNode<T> class

A read-only reactive node whose value is automatically derived from other ZenithNodes.

During the initial compute call and every subsequent re-computation, a ZenithZone observer is installed to auto-track which source nodes are read. When any tracked source changes, compute runs again and, if the result differs from the previous value, downstream subscribers are notified.

final firstName = ZenithNode<String>('John');
final lastName  = ZenithNode<String>('Doe');
final fullName  = ComputedNode<String>(
  () => '${firstName.value} ${lastName.value}',
);

// fullName.value == 'John Doe'
firstName.set('Jane');
// fullName.value == 'Jane Doe' — downstream ZenithBuilders rebuild.

Important: Do not call set on a ComputedNode. The value is managed exclusively by the compute function. Calling set will throw a StateError.

Inheritance
Implemented types
Available extensions

Constructors

ComputedNode(T _compute())
Creates a ComputedNode that derives its value from compute.

Properties

debugSubscriberCount → int
The current number of subscribers (including potentially dead weak references that have not yet been pruned).
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
isDisposed → bool
Whether this node has been disposed.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value ↔ T
The current value held by this node.
getter/setter pairinherited

Methods

dispose({bool purgeZeroize = false}) → void
Permanently disposes this node, clearing all subscribers.
override
guard(ZenithRef ref, Future<T> future()) → Future<void>

Available on ZenithNode<AsyncValue<T>>, provided by the SafeAsyncNodeX extension

Executes future and writes its result to this node, guarding every mutation with ref's lifecycle. Equivalent to ref.runAsync(this, future).
invalidate() → void
Forces a notification pass without changing the value.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifySubscribers() → void
Notifies all live subscribers that this node has changed.
inherited
onNodeChanged(ZenithNode node) → void
Called when any tracked source node changes.
override
onNodeRead(ZenithNode node, ZenithSubscription subscription) → void
Called when a ZenithNode.value getter is invoked while this tracker is the active ZenithZone.currentObserver.
override
set(T newValue) → void
Computed nodes are read-only. Calling set throws a StateError.
override
subscribe(ZenithSubscriber subscriber) → ZenithSubscription
Adds subscriber to this node's listener set.
inherited
toString() → String
A string representation of this object.
inherited
trySet(T newValue) → bool
Attempts to update the value of this node.
inherited
unsubscribe(ZenithSubscriber subscriber) → void
Removes subscriber from this node's listener set.
inherited
watch(ZenithRef ref, Stream<T> stream) → StreamSubscription<T>

Available on ZenithNode<AsyncValue<T>>, provided by the StreamNodeX extension

Subscribes to stream and writes each event to this node, guarding every mutation with ref's lifecycle.

Operators

operator ==(Object other) → bool
The equality operator.
inherited