Computed<T> constructor

Computed<T>(
  1. T compute()
)

Creates a Computed instance with the given computation function compute.

The compute function is executed immediately to initialize the value and is re-run automatically whenever any reactive dependencies it uses change.

Implementation

Computed(T Function() compute) {
  _observer = Observer(() {
    _value = compute();
  });

  // Register the current observer so dependencies can be tracked.
  Observer.current = _observer;
  _value = compute();
  Observer.current = null;
}