Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question:If I use TypedReducer,when will I use "Future"? #115

Closed
nyanboard opened this issue Mar 15, 2019 · 2 comments
Closed

Question:If I use TypedReducer,when will I use "Future"? #115

nyanboard opened this issue Mar 15, 2019 · 2 comments

Comments

@nyanboard
Copy link

nyanboard commented Mar 15, 2019

class UserModel {
String userName;
String password;
String token;
List roles;
UserModel({
this.userName,
this.password,
this.token,
this.roles,
});
factory UserModel.setUserInfo(String username,String password, String token,List roles) => UserModel(
userName: username,
password: password,
token: token,
roles: roles
);
}
final userReducer = combineReducers([
TypedReducer<UserModel, LoginByUserNameAction>(_loginByUserNameAction),
]);
Future _loginByUserNameAction(UserModel user, action) async {
var result = await loginByUsername(action.user.userName, action.user.password);
return UserModel.setUserInfo('123', 'password', 'token', []);
}
class LoginByUserNameAction {
final UserModel user;
LoginByUserNameAction(this.user);
}

@nyanboard
Copy link
Author

nyanboard commented Mar 15, 2019

A piece of my mind:
button click >>> dispatch >>> action(now,i use Future at there) >>> update state
but,There are some problems here at
final userReducer = combineReducers([
TypedReducer<UserModel, LoginByUserNameAction>(_loginByUserNameAction),
]);
Maybe I'm thinking the wrong way,so can you help me。
and my english is to bad。
。。。。。

@brianegan
Copy link
Owner

brianegan commented Mar 15, 2019

In general, reducers must be sync and they should not perform side-effects, such as loading data asynchronously from a database, web service, or login service. For those cases, use Middleware.

I'd recommend reading through the Docs we have on the Redux package to get an idea of how all these pieces fit together:

https://github.com/johnpryan/redux.dart#docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants