value property
The current state of the reactive object.
Reading this property automatically registers the object as a dependency
for the active observer (e.g., inside an LxComputed or LWatch build).
Implementation
@override
T get value {
if (_isActive) {
_ensureFresh();
return super.value;
}
// Pull-on-read mode
final existingProxy = Lx.proxy;
// If no proxy is listening, track for graph purposes (if middlewares are active)
if (existingProxy == null) {
if (!LevitReactiveMiddleware.hasGraphChangeMiddlewares) {
try {
return _compute();
} catch (e) {
throw e;
}
}
final tracker = _DependencyTracker()
..trackReactives = LevitReactiveMiddleware.hasGraphChangeMiddlewares;
Lx.proxy = tracker;
try {
T? computationResult;
try {
computationResult = _compute();
} catch (e) {
throw e;
}
// Notify middlewares of dependency graph change
if (tracker.reactives.isNotEmpty) {
maybeNotifyGraphChange(tracker.reactives);
}
return computationResult as T;
} finally {
Lx.proxy = null;
}
}
// Existing proxy is active (e.g., LWatch) - just compute
try {
return _compute();
} catch (e) {
throw e;
}
}