Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function*(action) {
while (true) {
try {
const { result } = yield api.loadReadModelState({
readModelName: 'HackerNews',
resolverName: 'story',
resolverArgs: { id: action.aggregateId }
})
if (JSON.parse(result) == null) {
yield delay(300)
continue
}
yield put(routerActions.push(`/storyDetails/${action.aggregateId}`))
break
} catch (error) {
// eslint-disable-next-line no-console
console.warn(error)
break
}
}
}
)
export function* init({ selectSpeakers, selectChapters, selectPlaytime }, { payload }) {
// Bump one cycle so chapters and speakers are available
yield delay(0)
const speakers = yield select(selectSpeakers)
const chapters = yield select(selectChapters)
const assignSpeakers = mapSpeakers(speakers)
const transcripts = compose(
sortBy(prop('start')),
concat(transformChapters(chapters)),
assignSpeakers,
transformTranscript,
getTranscripts
)(payload)
// don't run transcripts logic if no transcripts are available
if (transcripts.length <= chapters.length) {
return
}
// wait for editor to be ready
let ready: boolean = yield select(isReady)
while (!ready) {
const readyAction: SetEditorReadyAction = yield take(SET_EDITOR_READY)
ready = readyAction.payload.isReady
}
// wait for assets to load
let loading: boolean = yield select(isLoading)
while (loading) {
const loadingAction: SetEditorLoadingAction = yield take(SET_EDITOR_LOADING)
loading = loadingAction.payload.isLoading
}
// rendering leeway
yield delay(2000)
const screenshot = yield call(() => editorWindow.editor.takeScreenshot())
if (!screenshot) return
const thumbnail = yield call(() => resizeScreenshot(screenshot, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT))
if (!thumbnail) return
yield put(editProjectThumbnail(currentProject.id, thumbnail))
} catch (e) {
// skip screenshot
}
yield put(setScreenshotReady(true))
}
export function* successTimeoutSaga(action) {
try {
yield put(AlertActions.alertSuccess(action.params));
yield delay(5000);
yield put(AlertActions.alertClear());
} catch (error) {
yield put(AlertActions.alertClear());
}
}
*onLoad(): SagaIterator {
yield delay(2000, {});
}
function* createReleaseSaga({
tagName,
name,
body,
targetCommitish,
}: ICreateReleaseAction): SagaIterator {
try {
const responseData: any = yield call(post, releasesUrlPost, {
tagName,
name,
body,
targetCommitish,
});
yield delay(2000);
yield call(AppReleaseActionDispatcher.createAppReleaseFulfilled, responseData);
} catch (err) {
if (checkIfAxiosError(err)) {
const { response: { status } } = err as AxiosError;
yield call(AppReleaseActionDispatcher.createAppReleaseRejected, status);
}
}
}
yield put(updateClient(provider))
yield put(dumpCurrent())
window.location.reload(true)
}
yield put(updateClient(provider))
} else {
const currentUser = yield select(currentUserSelector)
if (currentUser !== 'NOT_SIGNIN') {
yield put(setUserAddress('NOT_SIGNIN'))
yield put(updateClient())
localStorage.removeItem('walletType')
yield put(dumpCurrent())
}
}
}
yield delay(1000)
}
}
function* req(url, options) {
var finalURL = API_ENDPOINT_URL + url
if (url.indexOf('/') == 0)
finalURL = APP_BASE_URL + url
else if (url.indexOf('http') == 0)
finalURL = url
for(let i = 0; i < API_RETRIES; i++){
try{
const winner = yield race({
req: call(fetchWrap, finalURL, options),
t: delay(API_TIMEOUT)
})
if (!winner.req)
throw new Error('timeout')
return winner.req;
}catch({message=''}){
if (message == 'timeout')
break;
else if(i < API_RETRIES-1) {
yield delay(100); //stop 100ms and try again
}
}
}
throw new Error('failed to load '+finalURL)
function* userFetcher(action: AsyncActionFetch) {
try {
yield put({ type: 'START_FETCH_USER' });
const response = yield call(() => fetch(`https://reqres.in/api/users/${action.id}?delay=1`));
yield put({ type: 'CONTINUE_FETCH_USER' });
const data = yield call(() => response.json());
yield delay(500);
const firstName = data.data.first_name;
if (typeof firstName !== 'string') throw new Error();
yield put({ type: 'FINISH_FETCH_USER', firstName });
} catch (e) {
yield put({ type: 'ERROR_FETCH_USER' });
}
}