value property

  1. @override
T value
override

Implementation

@override
T get value {
  if (_isComputing) {
    throw MobXCyclicReactionException(
        'Cycle detected in computation $name: $_fn');
  }

  if (!_context.isWithinBatch && _observers.isEmpty && !_keepAlive) {
    if (_context._shouldCompute(this)) {
      _context.startBatch();
      _value = computeValue(track: false);
      _context.endBatch();
    }
  } else {
    reportObserved();
    if (_context._shouldCompute(this)) {
      if (_trackAndCompute()) {
        _context._propagateChangeConfirmed(this);
      }
    }
  }

  if (_context._hasCaughtException(this)) {
    Error.throwWithStackTrace(_errorValue!, _errorValue!._stackTrace);
  }

  return _value as T;
}