<commit_before>import {normalize} from 'normalizr';
import isNode from 'detect-node';

const SUCCESS = 'SUCCESS';
const FAIL = 'FAIL';

export function actionCreator(type, ...params) {
  return (...args) => {
    return params.reduce((action, param, index) => {
      action.payload[param] = args[index];
      return action;
    }, {type, payload: {}});
  };
}

async function executeAsyncAction(type, config, payload, dispatch, args) {
  if (typeof config === 'function') config = {action: config}; // eslint-disable-line no-param-reassign
  const {client, server, schema} = config;
  const action = config.action || (isNode ? server : client);
  try {
    const response = await action(payload, dispatch, ...args);
    return dispatch({
      type: `${type}_${SUCCESS}`,
      payload,
      response: schema ? normalize(response, schema) : response
    });
  }
  catch (error) {
    return dispatch({type: `${type}_${FAIL}`, payload, error});
  }
}

export function asyncActionCreator(type, config) {
  return payload => async (dispatch, ...args) => {
    dispatch({type, payload});
    return await executeAsyncAction(type, config, payload, dispatch, args);
  };
}

export function asyncRoute(type, path, config, helpers) {
  const {client, server, schema, ...rest} = config;
  return {
    [type]: {
      path,
      thunk: async (dispatch, getState) => {
        const state = getState();
        const {location: {payload}} = state;
        return await executeAsyncAction(type, config, payload, dispatch, [getState, helpers]);
      },
      ...rest
    }
  };
}

export function createTypes(types, namespace) {
  return types.reduce((typeMap, type) => {
    typeMap[type] = namespace ? `${namespace}_${type}` : type;
    return typeMap;
  }, {});
}

export function createRouteTypes(types) {
  return createTypes(types, 'ROUTES');
}

export function async(type) {
  return [type, `${type}_${SUCCESS}`, `${type}_${FAIL}`];
}
<commit_msg>Remove reliance on async/await<commit_after>import {normalize} from 'normalizr';
import isNode from 'detect-node';

const SUCCESS = 'SUCCESS';
const FAIL = 'FAIL';

export function actionCreator(type, ...params) {
  return (...args) => {
    return params.reduce((action, param, index) => {
      action.payload[param] = args[index];
      return action;
    }, {type, payload: {}});
  };
}

function executeAsyncAction(type, config, payload, dispatch, args) {
  if (typeof config === 'function') config = {action: config}; // eslint-disable-line no-param-reassign
  const {client, server, schema} = config;
  const action = config.action || (isNode ? server : client);
  return action(payload, dispatch, ...args).then(
      response => dispatch({
        type: `${type}_${SUCCESS}`,
        payload,
        response: schema ? normalize(response, schema) : response
      }),
      error => dispatch({type: `${type}_${FAIL}`, payload, error}));
}

export function asyncActionCreator(type, config) {
  return payload => (dispatch, ...args) => {
    dispatch({type, payload});
    return executeAsyncAction(type, config, payload, dispatch, args);
  };
}

export function asyncRoute(type, path, config, helpers) {
  const {client, server, schema, ...rest} = config;
  return {
    [type]: {
      path,
      thunk: (dispatch, getState) => {
        const state = getState();
        const {location: {payload}} = state;
        return executeAsyncAction(type, config, payload, dispatch, [getState, helpers]);
      },
      ...rest
    }
  };
}

export function createTypes(types, namespace) {
  return types.reduce((typeMap, type) => {
    typeMap[type] = namespace ? `${namespace}_${type}` : type;
    return typeMap;
  }, {});
}

export function createRouteTypes(types) {
  return createTypes(types, 'ROUTES');
}

export function async(type) {
  return [type, `${type}_${SUCCESS}`, `${type}_${FAIL}`];
}

{'fraction_non_alphanumeric': 0.16502335236118318, 'fraction_numerical': 0.0, 'mean_word_length': 3.6167664670658684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '2167494', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1158, 'n_words': 313}