getComputed<T> function
Returns the current value of a computed node, recomputing it when dirty and linking it to the active subscriber.
Parameters:
computed: Node to read and potentially recompute
Example:
final myComputedNode = CustomComputedNode<int>(() => 0);
final value = getComputed(myComputedNode);
Implementation
@pragma("vm:prefer-inline")
@pragma("wasm:prefer-inline")
@pragma("dart2js:prefer-inline")
T getComputed<T>(ComputedReactiveNode<T> computed) {
final flags = computed.flags;
if (flags & (ReactiveFlags.dirty) != 0 ||
(flags & (ReactiveFlags.pending) != 0 &&
(checkDirty(computed.deps!, computed) ||
_removePending(computed, flags)))) {
if (updateComputed(computed)) {
final subs = computed.subs;
if (subs != null) {
shallowPropagate(subs);
}
JoltDebug.set(computed);
}
} else if (flags == (ReactiveFlags.none)) {
computed.flags = ReactiveFlags.mutable | ReactiveFlags.recursedCheck;
final prevSub = setActiveSub(computed);
try {
computed.pendingValue = computed.getter();
} finally {
activeSub = prevSub;
computed.flags &= ~ReactiveFlags.recursedCheck;
}
JoltDebug.set(computed);
}
final sub = activeSub;
if (sub != null) {
link(computed, sub, cycle);
}
JoltDebug.get(computed);
return computed.pendingValue as T;
}