Skip to content

Instantly share code, notes, and snippets.

@panthe
Last active November 13, 2020 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panthe/ab276f7df978b71393467437401102f0 to your computer and use it in GitHub Desktop.
Save panthe/ab276f7df978b71393467437401102f0 to your computer and use it in GitHub Desktop.
A typical Redux reducer
import 'package:redux/redux.dart';
import 'package:flutter_web_with_redux/redux/user/user_actions.dart';
import 'package:flutter_web_with_redux/redux/user/user_state.dart';
final userReducer = combineReducers<UserState>([
TypedReducer<UserState, FetchingUser>(_fetching),
TypedReducer<UserState, SetUser>(_setting),
TypedReducer<UserState, SavingUser>(_saving),
]);
UserState _fetching(UserState state, FetchingUser action){
return state.copyWith(
isFetching: action.isFetching
);
}
UserState _setting(UserState state, SetUser action){
return state.copyWith(
user: action.user
);
}
UserState _saving(UserState state, SavingUser action){
return state.copyWith(
isSaving: action.isSaving,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment