computedGetter<T> method

T computedGetter<T>(
  1. Computed<T> computed
)

Get the current value of a computed, updating if necessary

Implementation

@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
@pragma('dart2js:prefer-inline')
T computedGetter<T>(Computed<T> computed) {
  final flags = computed.flags;
  if (flags & 16 /** ReactiveFlags.dirty */ != 0 ||
      (flags & 32 /** ReactiveFlags.pending */ != 0 &&
          (checkDirty(computed.deps!, computed) ||
              _removePending(computed, flags)))) {
    if (updateComputed(computed)) {
      final subs = computed.subs;
      if (subs != null) {
        shallowPropagate(subs);
      }

      assert(() {
        getJoltDebugFn(computed)?.call(DebugNodeOperationType.set, computed);
        return true;
      }());
    }
  } else if (flags == 0 /* ReactiveFlags.none */) {
    computed.flags = 1 /* ReactiveFlags.mutable */;
    final prevSub = setActiveSub(computed);
    try {
      computed.pendingValue = computed.getter();
    } finally {
      activeSub = prevSub;
    }

    assert(() {
      getJoltDebugFn(computed)?.call(DebugNodeOperationType.set, computed);
      return true;
    }());
  }
  final sub = activeSub;
  if (sub != null) {
    link(computed, sub, cycle);
  }

  assert(() {
    getJoltDebugFn(computed)?.call(DebugNodeOperationType.get, computed);
    return true;
  }());

  return computed.pendingValue as T;
}