Selector<T, R> constructor
Selector<T, R> (
- Observable<
T> _source, - R _selector(
- T
- EqualityFunction<
R> ? equals, - ErrorCallback? onError,
Creates a new Selector that derives its value from the source observable.
The (selector) function is called whenever the source changes to compute the new value. Only changes in the selected value will trigger notifications to listeners.
Implementation
Selector(
this._source,
this._selector, {
EqualityFunction<R>? equals,
ErrorCallback? onError,
}) : super(
_computeInitialValue(_source, _selector),
equals: equals,
onError: onError,
) {
_listener = () {
MinixErrorHandler.safeExecute(() {
final newValue = _selector(_source.value);
// Use the inherited setter which handles equality checking
value = newValue;
}, onError: onError, context: 'Selector<$T, $R> update');
};
_source.addListener(_listener);
}