<commit_before>import {call, put, select, takeEvery} from 'redux-saga/effects';

import {fetchTaskHintData} from './server_module';

export default function (bundle, deps) {

    bundle.use('taskToken', 'taskRefresh');

    bundle.defineAction('requestHint', 'Hint.Request');
    bundle.defineAction('hintRequestFulfilled', 'Hint.Request.Fulfilled');
    bundle.defineAction('hintRequestRejected', 'Hint.Request.Rejected');

    bundle.addReducer('hintRequestFulfilled', function (state, action) {
        const {hints} = action;
        return {...state, hints};
    });

    bundle.addReducer('hintRequestRejected', function (state, action) {
        return {...state, hintRequestError: action.error};
    });

    bundle.addSaga(function* () {
        yield takeEvery(deps.requestHint, requestHintSaga);
    });

    function* requestHintSaga (action) {
            const task_token = yield call(platformAskHint, action.request);
            yield put({type: deps.taskToken, task_token});
            const host = yield select(state => state.options.server_module.host);
            const hints = yield call(fetchTaskHintData, host, task_token);
            if (hints) {
                yield put({type: deps.hintRequestFulfilled, hints});
                yield put({type: deps.taskRefresh});
            } else {
                yield put({type: deps.hintRequestRejected, error: 'server error'});
            }
    }

    function platformAskHint (hint_params) {
        return new Promise(resolve => {
            var tmp = window.task.updateToken;
            window.task.updateToken = function (task_token, callback) {
                callback();
                window.task.updateToken = tmp;
                resolve(task_token);
            };
            window.platform.askHint(hint_params);
        });
    }
}<commit_msg>whitespace<commit_after>import {call, put, select, takeEvery} from 'redux-saga/effects';

import {fetchTaskHintData} from './server_module';

export default function (bundle, deps) {

    bundle.use('taskToken', 'taskRefresh');

    bundle.defineAction('requestHint', 'Hint.Request');
    bundle.defineAction('hintRequestFulfilled', 'Hint.Request.Fulfilled');
    bundle.defineAction('hintRequestRejected', 'Hint.Request.Rejected');

    bundle.addReducer('hintRequestFulfilled', function (state, action) {
        const {hints} = action;
        return {...state, hints};
    });

    bundle.addReducer('hintRequestRejected', function (state, action) {
        return {...state, hintRequestError: action.error};
    });

    bundle.addSaga(function* () {
        yield takeEvery(deps.requestHint, requestHintSaga);
    });

    function* requestHintSaga (action) {
        const task_token = yield call(platformAskHint, action.request);
        yield put({type: deps.taskToken, task_token});
        const host = yield select(state => state.options.server_module.host);
        const hints = yield call(fetchTaskHintData, host, task_token);
        if (hints) {
            yield put({type: deps.hintRequestFulfilled, hints});
            yield put({type: deps.taskRefresh});
        } else {
            yield put({type: deps.hintRequestRejected, error: 'server error'});
        }
    }

    function platformAskHint (hint_params) {
        return new Promise(resolve => {
            var tmp = window.task.updateToken;
            window.task.updateToken = function (task_token, callback) {
                callback();
                window.task.updateToken = tmp;
                resolve(task_token);
            };
            window.platform.askHint(hint_params);
        });
    }
}
{'fraction_non_alphanumeric': 0.1263448275862069, 'fraction_numerical': 0.0, 'mean_word_length': 2.673758865248227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3024098', 'n_tokens_mistral': 1040, 'n_tokens_neox': 991, 'n_words': 206}