-
Notifications
You must be signed in to change notification settings - Fork 845
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
Showing
11 changed files
with
133 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:fish_redux/fish_redux.dart'; | ||
|
||
//TODO replace with your own action | ||
enum GlobalAction { action, changeThemeColor} | ||
|
||
class GlobalActionCreator { | ||
static Action onAction() { | ||
return const Action(GlobalAction.action); | ||
} | ||
|
||
static Action onchangeThemeColor(Color color){ | ||
return Action(GlobalAction.changeThemeColor, payload: color); | ||
} | ||
} |
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,16 @@ | ||
import 'package:fish_redux/fish_redux.dart'; | ||
import 'package:sample/global_store/reducer.dart'; | ||
import 'package:sample/global_store/state.dart'; | ||
|
||
class GlobalStore{ | ||
static Store<GlobalState> _globalStore; | ||
static GlobalState get state => store.getState(); | ||
|
||
static Store<GlobalState> get store{ | ||
if(null == _globalStore){ | ||
_globalStore = createStore<GlobalState>(initState(null), buildReducer()); | ||
} | ||
return _globalStore; | ||
} | ||
|
||
} |
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,26 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:fish_redux/fish_redux.dart'; | ||
|
||
import 'action.dart'; | ||
import 'state.dart'; | ||
|
||
Reducer<GlobalState> buildReducer() { | ||
return asReducer( | ||
<Object, Reducer<GlobalState>>{ | ||
GlobalAction.action: _onAction, | ||
GlobalAction.changeThemeColor: _onchangeThemeColor, | ||
}, | ||
); | ||
} | ||
|
||
GlobalState _onAction(GlobalState state, Action action) { | ||
final GlobalState newState = state.clone(); | ||
return newState; | ||
} | ||
|
||
GlobalState _onchangeThemeColor(GlobalState state, Action action) { | ||
final GlobalState newState = state.clone(); | ||
newState.themeColor = action.payload as Color; | ||
return newState; | ||
} |
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,15 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:fish_redux/fish_redux.dart'; | ||
|
||
class GlobalState implements Cloneable<GlobalState> { | ||
Color themeColor; | ||
@override | ||
GlobalState clone() { | ||
return GlobalState(); | ||
} | ||
} | ||
|
||
GlobalState initState(Map<String, dynamic> args) { | ||
return GlobalState(); | ||
} |
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,16 +1,20 @@ | ||
import 'package:fish_redux/fish_redux.dart'; | ||
|
||
enum ToDoEditAction { update, done } | ||
enum ToDoEditAction { update, done, changeTheme } | ||
|
||
class ToDoEditActionCreator { | ||
static Action update(String name, String desc) { | ||
static Action update(String name, String desc, String themeidx) { | ||
return Action( | ||
ToDoEditAction.update, | ||
payload: <String, String>{'name': name, 'desc': desc}, | ||
payload: <String, String>{'name': name, 'desc': desc, 'themeidx' : themeidx}, | ||
); | ||
} | ||
|
||
static Action done() { | ||
return const Action(ToDoEditAction.done); | ||
} | ||
|
||
static Action changeTheme(){ | ||
return Action(ToDoEditAction.changeTheme); | ||
} | ||
} |
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