Created
November 8, 2016 20:53
-
-
Save MrRhodes/6495131049bb7d76120138564046f73e to your computer and use it in GitHub Desktop.
Immutable reducer.
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
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