get method

T get()

Gets the computed value, recalculating if necessary.

Checks if the value is dirty or pending, and if so, re-runs the getter function. Automatically tracks dependencies accessed during computation.

Returns the computed value.

Implementation

T get() {
  final flags = this.flags;
  // dart format off
  if (
    (flags & ReactiveFlags.dirty) != ReactiveFlags.none
    || (
      (flags & ReactiveFlags.pending) != ReactiveFlags.none
      && (
        checkDirty(deps!, this)
        || identical(this.flags = flags & -33 /*~ReactiveFlags.pending*/, false)
      )
    )
  ) { // dart format on
    if (didUpdate()) {
      final subs = this.subs;
      if (subs != null) {
        shallowPropagate(subs);
      }
    }
  } else if (flags == ReactiveFlags.none) {
    this.flags =
        5 /*ReactiveFlags.mutable | ReactiveFlags.recursedCheck*/
            as ReactiveFlags;
    final prevSub = setActiveSub(this);
    try {
      currentValue = getter(null);
    } finally {
      activeSub = prevSub;
      this.flags &= -5 /*~ReactiveFlags.recursedCheck*/;
    }
  }

  final sub = activeSub;
  if (sub != null) link(this, sub, cycle);

  return currentValue as T;
}