obsComputed<T> method
Create and auto-track a computed reactive value - PREVENTS MEMORY LEAKS
Automatically disposed when this controller is disposed, preventing
lingering listeners on global services or shared reactive state.
Works cleanly in both late final fields and onInit() without
colliding with the top-level computed() helper.
Example:
class CartController extends ZenController {
final items = <CartItem>[].obs();
late final total = obsComputed(() =>
items.value.fold(0.0, (sum, i) => sum + i.price));
}
Implementation
RxComputed<T> obsComputed<T>(T Function() computation) {
if (_disposed) {
throw StateError('Cannot create computed value on disposed controller');
}
final rxComputed = RxComputed<T>(computation);
_trackComputedObject(rxComputed);
return rxComputed;
}