Skip to content

Commit

Permalink
use reselect in example
Browse files Browse the repository at this point in the history
  • Loading branch information
zjuwjf committed May 24, 2019
1 parent 6132b9b commit 8e3c8c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 18 additions & 8 deletions example/lib/todo_list_page/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@ PageState initState(Map<String, dynamic> args) {
return PageState();
}

class ReportConnector extends ConnOp<PageState, ReportState> {
class ReportConnector extends Reselect2<PageState, ReportState, int, int> {
@override
ReportState get(PageState state) {
final ReportState reportState = ReportState();
reportState.total = state.toDos.length;
reportState.done =
state.toDos.where((ToDoState tds) => tds.isDone).toList().length;
return reportState;
ReportState computed(int sub0, int sub1) {
return ReportState()
..done = sub0
..total = sub1;
}

@override
void set(PageState state, ReportState subState) {}
int getSub0(PageState state) {
return state.toDos.where((ToDoState tds) => tds.isDone).toList().length;
}

@override
int getSub1(PageState state) {
return state.toDos.length;
}

@override
void set(PageState state, ReportState subState) {
throw Exception('Unexcepted to set PageState from ReportState');
}
}
4 changes: 3 additions & 1 deletion lib/src/redux_connector/reselect.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '../redux/redux.dart';
import 'op_mixin.dart';

bool _listEquals(List<dynamic> list1, List<dynamic> list2) {
if (identical(list1, list2)) {
Expand All @@ -24,7 +25,8 @@ bool _listEquals(List<dynamic> list1, List<dynamic> list2) {
return true;
}

abstract class _BasicReselect<T, P> extends MutableConn<T, P> {
abstract class _BasicReselect<T, P> extends MutableConn<T, P>
with ConnOpMixin<T, P> {
List<dynamic> _subsCache;
P _pCache;
bool _hasBeenCalled = false;
Expand Down

0 comments on commit 8e3c8c0

Please sign in to comment.