Skip to content

Instantly share code, notes, and snippets.

@MrRhodes
Created November 8, 2016 20:53
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 MrRhodes/6495131049bb7d76120138564046f73e to your computer and use it in GitHub Desktop.
Save MrRhodes/6495131049bb7d76120138564046f73e to your computer and use it in GitHub Desktop.
Immutable reducer.
const initialState = new Immutable.Map({
email: '',
password: '',
isLoggingIn: false,
isLoggedIn: false,
error: null
});
export default function user(state = initialState, action) {
switch (action.type) {
case LOGIN_ATTEMPT:
return state.merge({
isLoggingIn: true,
isLoggedIn: false,
email: action.email,
password: action.password // Note you shouldn't store user's password in real apps
});
case LOGGED_FAILED:
return state.merge({
error: action.error,
isLoggingIn: false,
isLoggedIn: false
});
case LOGGED_SUCCESSFULLY:
return state.merge({
error: null,
isLoggingIn: false,
isLoggedIn: true
});
break;
default:
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment