Created
June 26, 2018 22:24
-
-
Save eduardomoroni/87bc6c509a1fa4fe3c913ded49a8cb51 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
import { all, call, put, takeLatest } from "redux-saga/effects"; | |
import { Credential, User } from "../../entities"; | |
import { updateUserAction } from "./user"; | |
import { SignInInteractor } from "../../useCases"; | |
import { SampleService } from "../../services"; | |
export const SIGN_IN = "user/saga/sign_in"; | |
interface SignInActionType { | |
type: string; | |
credential: Credential; | |
} | |
export const signInAction = (credential: Credential): SignInActionType => ({ | |
type: SIGN_IN, | |
credential, | |
}); | |
function* signInSaga(action: SignInActionType) { | |
const { credential } = action; | |
try { | |
const service = new SampleService(); | |
const interactor = new SignInInteractor(service); | |
const user = yield interactor.signIn(credential); | |
yield put(updateUserAction(user)); // This action simplily saves User into state | |
} catch (error) { | |
console.error(error); | |
// DO SOMETHING ELSE | |
} | |
} | |
export function* rootSaga() { | |
yield all([takeLatest(SIGN_IN, signInSaga)]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment