forked from alibaba/fish-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zjuwjf
committed
May 26, 2019
1 parent
612ef0a
commit fd59f60
Showing
15 changed files
with
68 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...e/lib/global_store/global_base_state.dart → example/lib/global_store/base_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import 'package:fish_redux/fish_redux.dart'; | ||
import 'package:sample/global_store/state.dart'; | ||
import 'state.dart'; | ||
|
||
/// Definition of Cloneable | ||
mixin GlobalBaseState<T extends Cloneable<T>> implements Cloneable<T> { | ||
T lessClone(GlobalState state); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:fish_redux/fish_redux.dart'; | ||
import 'reducer.dart'; | ||
import 'state.dart'; | ||
|
||
class GlobalStore { | ||
static Store<GlobalState> _globalStore; | ||
|
||
static Store<GlobalState> get store => | ||
_globalStore ??= createStore<GlobalState>(GlobalState(), buildReducer()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import 'package:fish_redux/fish_redux.dart'; | ||
|
||
enum ToDoEditAction { update, done, changeTheme } | ||
enum ToDoEditAction { update, onDone, onChangeTheme } | ||
|
||
class ToDoEditActionCreator { | ||
static Action update(String name, String desc, String themeidx) { | ||
return Action( | ||
ToDoEditAction.update, | ||
payload: <String, String>{'name': name, 'desc': desc, 'themeidx' : themeidx}, | ||
payload: <String, String>{ | ||
'name': name, | ||
'desc': desc, | ||
'themeidx': themeidx | ||
}, | ||
); | ||
} | ||
|
||
static Action done() { | ||
return const Action(ToDoEditAction.done); | ||
static Action onDone() { | ||
return const Action(ToDoEditAction.onDone); | ||
} | ||
|
||
static Action changeTheme(){ | ||
return Action(ToDoEditAction.changeTheme); | ||
static Action onChangeTheme() { | ||
return const Action(ToDoEditAction.onChangeTheme); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
import 'package:fish_redux/fish_redux.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:sample/global_store/action.dart'; | ||
import 'package:sample/global_store/global_store.dart'; | ||
|
||
import '../global_store/action.dart'; | ||
import '../global_store/store.dart'; | ||
import '../todo_list_page/todo_component/component.dart'; | ||
import 'action.dart'; | ||
import 'state.dart'; | ||
|
||
Effect<TodoEditState> buildEffect() { | ||
return combineEffects(<Object, Effect<TodoEditState>>{ | ||
Lifecycle.initState: _init, | ||
ToDoEditAction.done: _onDone, | ||
ToDoEditAction.changeTheme : _onchangeTheme, | ||
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, null)); | ||
ctx.dispatch(ToDoEditActionCreator.update( | ||
ctx.state.nameEditController.text, null, null)); | ||
}); | ||
|
||
ctx.state.descEditController.addListener(() { | ||
ctx.dispatch( | ||
ToDoEditActionCreator.update(null, ctx.state.descEditController.text, null)); | ||
ctx.dispatch(ToDoEditActionCreator.update( | ||
null, ctx.state.descEditController.text, null)); | ||
}); | ||
} | ||
|
||
void _onDone(Action action, Context<TodoEditState> ctx) { | ||
Navigator.of(ctx.context).pop<ToDoState>(ctx.state.toDo); | ||
} | ||
|
||
void _onchangeTheme(Action action, Context<TodoEditState> ctx) { | ||
void _onChangeTheme(Action action, Context<TodoEditState> ctx) { | ||
ctx.state.themeIdx++; | ||
if(ctx.state.themeIdx >= ctx.state.themeColorSlots.length) | ||
{ | ||
if (ctx.state.themeIdx >= ctx.state.themeColorSlots.length) { | ||
ctx.state.themeIdx = 0; | ||
} | ||
//change global data | ||
GlobalStore.store.dispatch(GlobalActionCreator.onchangeThemeColor(ctx.state.themeColorSlots[ctx.state.themeIdx])); | ||
GlobalStore.store.dispatch(GlobalActionCreator.onchangeThemeColor( | ||
ctx.state.themeColorSlots[ctx.state.themeIdx])); | ||
//notify todo edit page update data | ||
ToDoEditActionCreator.update(null, null, ctx.state.themeIdx.toString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters