fb-test-module
Version:
How to use: ``` import {store, getStore} from 'fb-test-module'; conf.DialogramApi = "API_BASE_URL"; conf.Platform = "mobile"; //use "web" if you are on webApp getStore(); //Inject store in your provider ``` and you'r readyt to go. # Base ## Act
34 lines (30 loc) • 1.13 kB
text/typescript
import { put, takeLatest, call, all } from 'redux-saga/effects';
import { callApi } from './axios';
import { ApiType, LOG_OUT } from './BaseType';
import { SuccessApiCall, FailureApiCall, LoadingApiCall, setEntity } from './BaseAction';
import { removeSession } from './Session/Actions';
import { removeUser } from './User/Actions';
import { ERROR } from './Error';
export function* ApiMonitor(action: any): any {
try {
yield put(LoadingApiCall(action.payload.meta.entity));
const response = yield call(callApi, action.payload.meta);
yield put(setEntity(action, response))
yield put(SuccessApiCall(action.payload.meta.entity));
} catch (error) {
yield put(FailureApiCall(action.payload.meta.entity, error.response.status, ERROR[error.response.status]));
}
}
export function* LogOutMonitor(action: any): any {
yield put(removeSession());
yield put(removeUser());
}
function* actionWatcher() {
yield takeLatest(ApiType.Dialogram, ApiMonitor);
yield takeLatest(LOG_OUT, LogOutMonitor);
}
export function* rootSaga(): any {
yield all([
actionWatcher(),
]);
}