Last active
April 23, 2018 08:48
-
-
Save hrdtbs/b1afb517d2d57342a03ca7edcc6c294f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export { default as login } from "./login"; | |
export { default as auth } from "./auth"; |
This file contains hidden or 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
import { createActions } from "redux-actions"; | |
const login = createActions({ | |
LOGIN: { | |
REQUEST: (...payload) => payload, | |
RESPONSE: payload => payload | |
} | |
}).login; | |
export default login; |
This file contains hidden or 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
import { routerReducer } from "react-router-redux"; | |
import { combineReducers } from "redux"; | |
import loginReducer from "./loginReducer"; | |
export default combineReducers({ | |
login: loginReducer, | |
router: routerReducer | |
}); |
This file contains hidden or 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
import { handleActions } from "redux-actions"; | |
import { login } from "../actions"; | |
export default handleActions( | |
{ | |
[login.response().type]: (state, action) => { | |
return { | |
...state, | |
...action.payload | |
}; | |
} | |
}, | |
{ | |
currentUser: undefined, | |
error: undefined | |
} | |
); |
This file contains hidden or 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
import {loginSaga} from "./loginSaga" | |
import {login} from "./actions" | |
function* Saga() { | |
yield takeLatest(login.request().type, loginSaga); | |
yield takeLatest(auth.request().type, authSaga); | |
} | |
export default Saga; |
This file contains hidden or 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
import { call, put, takeLatest } from "redux-saga/effects"; | |
import { login } from "../actions"; | |
import firebase from "_firebase"; | |
function loginMock(email, password) { | |
return new Promise((resolve, reject) => { | |
firebase | |
.auth() | |
.signInWithEmailAndPassword(email, password) | |
.catch(error => { | |
reject(error); | |
}) | |
.then(() => { | |
const currentUser = firebase.auth().currentUser; | |
resolve(currentUser); | |
}); | |
}); | |
} | |
function* loginSaga({ payload: { email, password } }) { | |
try { | |
// call : Promiseの完了を待つ | |
const currentUser = yield call(loginMock, email, password); | |
// put : Actionをdispatchする | |
yield put(login.response({ currentUser: currentUser })); | |
} catch (error) { | |
// put : Actionをdispatchする | |
yield put(login.response({ error: error })); | |
} | |
} | |
export default loginSaga; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment