Skip to content

Instantly share code, notes, and snippets.

@eduardomoroni
Created June 26, 2018 22:24
Show Gist options
  • Save eduardomoroni/87bc6c509a1fa4fe3c913ded49a8cb51 to your computer and use it in GitHub Desktop.
Save eduardomoroni/87bc6c509a1fa4fe3c913ded49a8cb51 to your computer and use it in GitHub Desktop.
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