Skip to content

Commit

Permalink
Merge pull request #96 from LoveCommunity/feature/computed2
Browse files Browse the repository at this point in the history
add configurable `Computed2`
  • Loading branch information
beeth0ven committed Jul 26, 2022
2 parents 854ffa5 + cf147a9 commit 6a84185
Show file tree
Hide file tree
Showing 2 changed files with 422 additions and 17 deletions.
39 changes: 38 additions & 1 deletion lib/src/scopes/configurables/computed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Computed<T, R> extends FinalStatesBase<R> {
Computed({
Object? name,
Object? statesName,
required R Function(ScopeGet scope, T) compute,
required R Function(ScopeGet scope, T it) compute,
Equals<R>? equals,
bool late = true,
}): super(
Expand All @@ -25,6 +25,27 @@ class Computed<T, R> extends FinalStatesBase<R> {
);
}

class Computed2<T1, T2, R> extends FinalStatesBase<R> {

Computed2({
Object? name,
Object? statesName1,
Object? statesName2,
required R Function(ScopeGet scope, T1 it1, T2 it2) compute,
Equals<R>? equals,
bool late = true,
}): super(
name: name,
equal: _superEqual2<T1, T2, R>(
statesName1,
statesName2,
compute,
equals,
),
late: late,
);
}

Equal<States<R>> _superEqual<T, R>(
Object? statesName,
R Function(ScopeGet scope, T) compute,
Expand All @@ -37,3 +58,19 @@ Equal<States<R>> _superEqual<T, R>(
equals: equals,
);
}

Equal<States<R>> _superEqual2<T1, T2, R>(
Object? statesName1,
Object? statesName2,
R Function(ScopeGet scope, T1 it1, T2 it2) compute,
Equals<R>? equals,
) {
return (scope) => States
.combine2<T1, T2, R>(
states1: scope.get<States<T1>>(name: statesName1),
states2: scope.get<States<T2>>(name: statesName2),
combiner: (it1, it2) => compute(scope, it1, it2),
)
.distinct(equals);
}

0 comments on commit 6a84185

Please sign in to comment.