notifyComputed<T> function

void notifyComputed<T>(
  1. ComputedReactiveNode<T> computed, [
  2. bool force = false
])

Invalidates a computed node and notifies its subscribers.

This function recomputes the value and notifies subscribers based on the force parameter. When force is false (soft update), subscribers are only notified if the value actually changed. When force is true (force update), subscribers are notified regardless of whether the value changed.

Parameters:

  • computed: Node to invalidate and notify
  • force: If true, forces notification even if the value hasn't changed

Example:

final cacheBustingComputed = CustomComputedNode<int>(() => 0);
notifyComputed(cacheBustingComputed, false); // Soft update
notifyComputed(cacheBustingComputed, true); // Force update

Implementation

@pragma("vm:prefer-inline")
@pragma("wasm:prefer-inline")
@pragma("dart2js:prefer-inline")
void notifyComputed<T>(ComputedReactiveNode<T> computed, [bool force = false]) {
  final updated = updateComputed(computed);

  if (!force && !updated) return;

  var subs = computed.subs;

  while (subs != null) {
    subs.sub.flags |= ReactiveFlags.pending;
    shallowPropagate(subs);
    subs = subs.nextSub;
  }

  if (computed.subs != null && batchDepth == 0) {
    flushEffects();
  }

  JoltDebug.notify(computed);
}