create1
ResettableSelector<
- T1
Creates a resettable selector with one input.
Implementation
static ResettableSelector<S, R> create1<S, T1, R>(
Selector<S, T1> selector1,
R Function(T1) combiner,
) {
T1? lastInput;
R? lastResult;
var hasCache = false;
void reset() {
lastInput = null;
lastResult = null;
hasCache = false;
}
R select(S state) {
final input = selector1(state);
if (hasCache && identical(input, lastInput)) {
return lastResult as R;
}
lastInput = input;
lastResult = combiner(input);
hasCache = true;
return lastResult as R;
}
return ResettableSelector._(select, reset);
}