From 8e3c8c0321c8b76ea15d3559324cb2d3b477f1b1 Mon Sep 17 00:00:00 2001 From: zjuwjf <> Date: Fri, 24 May 2019 11:58:34 +0800 Subject: [PATCH] use reselect in example --- example/lib/todo_list_page/state.dart | 26 ++++++++++++++++++-------- lib/src/redux_connector/reselect.dart | 4 +++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/example/lib/todo_list_page/state.dart b/example/lib/todo_list_page/state.dart index ed7a9e9..72adb28 100644 --- a/example/lib/todo_list_page/state.dart +++ b/example/lib/todo_list_page/state.dart @@ -16,16 +16,26 @@ PageState initState(Map args) { return PageState(); } -class ReportConnector extends ConnOp { +class ReportConnector extends Reselect2 { @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'); + } } diff --git a/lib/src/redux_connector/reselect.dart b/lib/src/redux_connector/reselect.dart index aef66ca..be5d2cd 100644 --- a/lib/src/redux_connector/reselect.dart +++ b/lib/src/redux_connector/reselect.dart @@ -1,4 +1,5 @@ import '../redux/redux.dart'; +import 'op_mixin.dart'; bool _listEquals(List list1, List list2) { if (identical(list1, list2)) { @@ -24,7 +25,8 @@ bool _listEquals(List list1, List list2) { return true; } -abstract class _BasicReselect extends MutableConn { +abstract class _BasicReselect extends MutableConn + with ConnOpMixin { List _subsCache; P _pCache; bool _hasBeenCalled = false;