Skip to content

Commit

Permalink
example optimization alibaba#492
Browse files Browse the repository at this point in the history
  • Loading branch information
zjuwjf committed Oct 12, 2019
1 parent a4a5d06 commit 9f358b5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 47 deletions.
5 changes: 3 additions & 2 deletions example/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Widget createApp() {
/// 建立 AppStore 驱动 PageStore 的单向数据连接
/// 1. 参数1 AppStore
/// 2. 参数2 当 AppStore.state 变化时, PageStore.state 该如何变化
page.connectExtraStore<GlobalState>(GlobalStore.store, (Object pagestate, GlobalState appState) {
page.connectExtraStore<GlobalState>(GlobalStore.store,
(Object pagestate, GlobalState appState) {
final GlobalBaseState p = pagestate;
if (p.themeColor != appState.themeColor) {
if (pagestate is Cloneable) {
Expand Down Expand Up @@ -55,7 +56,7 @@ Widget createApp() {
],

/// Effect AOP
effectMiddleware: [
effectMiddleware: <EffectMiddleware<dynamic>>[
_pageAnalyticsMiddleware<dynamic>(),
],

Expand Down
12 changes: 1 addition & 11 deletions example/lib/todo_edit_page/action.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import 'package:fish_redux/fish_redux.dart';

enum ToDoEditAction { update, onDone, onChangeTheme }
enum ToDoEditAction { onDone, onChangeTheme }

class ToDoEditActionCreator {
static Action update(String name, String desc) {
return Action(
ToDoEditAction.update,
payload: <String, String>{
'name': name,
'desc': desc,
},
);
}

static Action onDone() {
return const Action(ToDoEditAction.onDone);
}
Expand Down
20 changes: 5 additions & 15 deletions example/lib/todo_edit_page/effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,19 @@ import 'state.dart';

Effect<TodoEditState> buildEffect() {
return combineEffects(<Object, Effect<TodoEditState>>{
Lifecycle.initState: _init,
ToDoEditAction.onDone: _onDone,
ToDoEditAction.onChangeTheme: _onChangeTheme,
});
}

void _init(Action action, Context<TodoEditState> ctx) {
ctx.state.nameEditController.addListener(() {
ctx.dispatch(
ToDoEditActionCreator.update(ctx.state.nameEditController.text, null));
});

ctx.state.descEditController.addListener(() {
ctx.dispatch(
ToDoEditActionCreator.update(null, ctx.state.descEditController.text));
});
}

void _onDone(Action action, Context<TodoEditState> ctx) {
Navigator.of(ctx.context).pop<ToDoState>(ctx.state.toDo);
Navigator.of(ctx.context).pop<ToDoState>(
ctx.state.toDo.clone()
..desc = ctx.state.descEditController.text
..title = ctx.state.nameEditController.text,
);
}

void _onChangeTheme(Action action, Context<TodoEditState> ctx) {
//change global data
GlobalStore.store.dispatch(GlobalActionCreator.onchangeThemeColor());
}
2 changes: 0 additions & 2 deletions example/lib/todo_edit_page/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:fish_redux/fish_redux.dart';

import '../todo_list_page/todo_component/component.dart';
import 'effect.dart';
import 'reducer.dart';
import 'state.dart';
import 'view.dart';

Expand All @@ -11,7 +10,6 @@ class TodoEditPage extends Page<TodoEditState, ToDoState> {
: super(
initState: initState,
effect: buildEffect(),
reducer: buildReducer(),
view: buildView,

/// 页面私有AOP,如果需要
Expand Down
17 changes: 0 additions & 17 deletions example/lib/todo_edit_page/reducer.dart

This file was deleted.

0 comments on commit 9f358b5

Please sign in to comment.