fix: use document from store context

This commit is contained in:
Valeriy
2019-01-09 03:36:45 +03:00
committed by Stuart Taylor
parent b59c7cfed0
commit d263ed4ed7
2 changed files with 13 additions and 5 deletions

View File

@ -11,7 +11,11 @@ import { isBrowser } from '../../utils';
const clientSide = isBrowser();
const sagaMiddleware = createSagaMiddleware();
const sagaMiddleware = createSagaMiddleware({
context: {
document: clientSide ? document : {}
}
});
const epicMiddleware = createEpicMiddleware({
dependencies: {
window: clientSide ? window : {},

View File

@ -4,7 +4,8 @@ import {
call,
takeLatest,
takeEvery,
fork
fork,
getContext
} from 'redux-saga/effects';
import { delay, channel } from 'redux-saga';
@ -99,15 +100,16 @@ function* executeJSChallengeSaga(state, proxyLogger) {
}
}
function createTestFrame(ctx, proxyLogger) {
function createTestFrame(document, ctx, proxyLogger) {
return new Promise(resolve =>
createTestFramer(document, resolve, proxyLogger)(ctx)
);
}
function* executeDOMChallengeSaga(state, proxyLogger) {
const document = yield getContext('document');
const ctx = yield call(buildDOMChallenge, state);
yield call(createTestFrame, ctx, proxyLogger);
yield call(createTestFrame, document, ctx, proxyLogger);
// wait for a code execution on a "ready" event in jQuery challenges
yield delay(100);
@ -118,8 +120,9 @@ function* executeDOMChallengeSaga(state, proxyLogger) {
// TODO: use a web worker
function* executeBackendChallengeSaga(state, proxyLogger) {
const document = yield getContext('document');
const ctx = yield call(buildBackendChallenge, state);
yield call(createTestFrame, ctx, proxyLogger);
yield call(createTestFrame, document, ctx, proxyLogger);
return yield call(executeTests, (testString, testTimeout) =>
runTestInTestFrame(document, testString, testTimeout)
@ -166,6 +169,7 @@ function* updateMainSaga() {
}
const state = yield select();
const ctx = yield call(buildDOMChallenge, state);
const document = yield getContext('document');
const frameMain = yield call(createMainFramer, document);
yield call(frameMain, ctx);
} catch (err) {