redux-saga/effects#CallEffect TypeScript Examples
The following examples show how to use
redux-saga/effects#CallEffect.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts From slice-machine with Apache License 2.0 | 5 votes |
// Sagas
function* checkSetupSaga(
action: ReturnType<typeof checkSimulatorSetupCreator.request>
) {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { data: setupStatus }: { data: SimulatorCheckResponse } = yield call(
checkSimulatorSetup
);
// All the backend checks are ok ask for the frontend Iframe check
if ("ok" === setupStatus.manifest && "ok" === setupStatus.dependencies) {
yield put(
checkSimulatorSetupCreator.success({
setupStatus: { iframe: null, ...setupStatus },
})
);
yield put(connectToSimulatorIframeCreator.request());
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const {
timeout,
iframeCheckKO,
iframeCheckOk,
}: {
iframeCheckOk: ReturnType<
typeof connectToSimulatorIframeCreator.success
>;
iframeCheckKO: ReturnType<
typeof connectToSimulatorIframeCreator.failure
>;
timeout: CallEffect<true>;
} = yield race({
iframeCheckOk: take(getType(connectToSimulatorIframeCreator.success)),
iframeCheckKO: take(getType(connectToSimulatorIframeCreator.failure)),
timeout: delay(10000),
});
if (iframeCheckOk && action.payload.callback) {
action.payload.callback();
return;
}
if (timeout) {
yield put(connectToSimulatorIframeCreator.failure());
yield call(failCheckSetupSaga);
return;
}
if (iframeCheckKO) {
yield call(failCheckSetupSaga);
return;
}
return;
}
// All the backend checks are ko and the request is coming from the "start"
const isTheFirstTime =
"ko" === setupStatus.manifest &&
"ko" === setupStatus.dependencies &&
action.payload.withFirstVisitCheck;
if (isTheFirstTime) {
yield put(openSetupDrawerCreator({}));
return;
}
yield put(
checkSimulatorSetupCreator.success({
setupStatus: { iframe: null, ...setupStatus },
})
);
yield call(failCheckSetupSaga);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
yield put(checkSimulatorSetupCreator.failure(error as Error));
}
}