Computed<T> constructor
Constructs a new Computed instance.
_sources
is a list of Reactive instances whose values are used to compute the new value.
_compute
is a function that takes the list of Reactive instances and computes the new value.
Implementation
Computed(this._sources, this._compute) {
_value = _compute(_sources);
_controller.add(Snapshot(_value, _value));
StreamGroup.merge(_sources.map((source) => source.stream)).listen((_) {
final newValue = _compute(_sources);
if (newValue != _value) {
_value = newValue;
_controller.add(Snapshot(_value, newValue));
}
});
}