Skip to content

Commit

Permalink
add call
Browse files Browse the repository at this point in the history
  • Loading branch information
hyjfine committed Mar 21, 2019
1 parent 0c2afeb commit 0533b5f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/screens/todo_detail/effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_app_redux/screens/todo_detail/action.dart';
import 'package:flutter_app_redux/screens/todo_detail/state.dart';
import 'package:flutter_app_redux/services/main.dart';
import 'package:flutter_app_redux/services/todo_detail_repository.dart';
import 'package:flutter_app_redux/utils/store_util.dart';

Effect<TodoDetailState> buildEffect() {
return combineEffects(<Object, Effect<TodoDetailState>>{
Expand All @@ -17,6 +18,7 @@ void _init(Action action, Context<TodoDetailState> ctx) {
}

void _fetch(Action action, Context<TodoDetailState> ctx) {
StoreUtil.globalStore.dispatch(AppActionCreator.logout());
Services.asyncRequest(
ctx.dispatch,
() => TodoDetailRepository.fetchTodo(action.payload),
Expand Down
2 changes: 2 additions & 0 deletions lib/screens/todo_list/effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_app_redux/screens/todo_list/action.dart';
import 'package:flutter_app_redux/screens/todo_list/state.dart';
import 'package:flutter_app_redux/services/main.dart';
import 'package:flutter_app_redux/services/todo_list_repository.dart';
import 'package:flutter_app_redux/utils/store_util.dart';

Effect<TodoListState> buildEffect() {
return combineEffects(<Object, Effect<TodoListState>>{
Expand All @@ -28,6 +29,7 @@ void _fetch(Action action, Context<TodoListState> ctx) {
}

void _add(Action action, Context<TodoListState> ctx) {
StoreUtil.globalStore.dispatch(AppActionCreator.login('effect', 'token success!'));
Services.asyncRequest(
ctx.dispatch,
() => TodoListRepository.postTodoList(),
Expand Down
10 changes: 7 additions & 3 deletions lib/utils/store_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,23 @@ Reducer<AppState> buildReducer() {

AppState _login(AppState state, Action action) {
final AppState newState = state.clone();

newState.userName = action.payload['name'];
newState.token = action.payload['token'];

return newState;
}

AppState _logout(AppState state, Action action) {
final AppState newState = state.clone();
final AppState newState = initState('empty');
return newState;
}

enum AppAction { login, logout }

class AppActionCreator {
static Action login() {
return Action(AppAction.login);
static Action login(String name, String token) {
return Action(AppAction.login, payload: {'name': name, 'token': token});
}

static Action logout() {
Expand Down

0 comments on commit 0533b5f

Please sign in to comment.