createSelector3
Selector<
- T1,
- T2,
- T3
Creates a memoized selector with three input selectors.
Implementation
Selector<S, R> createSelector3<S, T1, T2, T3, R>(
Selector<S, T1> selector1,
Selector<S, T2> selector2,
Selector<S, T3> selector3,
R Function(T1, T2, T3) combiner,
) {
T1? lastInput1;
T2? lastInput2;
T3? lastInput3;
R? lastResult;
var hasCache = false;
return (S state) {
final input1 = selector1(state);
final input2 = selector2(state);
final input3 = selector3(state);
if (hasCache &&
identical(input1, lastInput1) &&
identical(input2, lastInput2) &&
identical(input3, lastInput3)) {
return lastResult as R;
}
lastInput1 = input1;
lastInput2 = input2;
lastInput3 = input3;
lastResult = combiner(input1, input2, input3);
hasCache = true;
return lastResult as R;
};
}