<commit_before>import enhanceReducer from './enhanceReducer';

/**
 * Creates enhanced store factory, which takes original `createStore` as argument.
 * Returns modified store which is capable of handling Reducers in form of Generators.
 *
 * @param {Function} Original createStore implementation to be enhanced
 * @returns {Function} Store factory
 */
export default createStore => (rootReducer, initialState) => {
  let store = null;
  let replacing = false;

  const deferEffects = effects => {
    if (!replacing) {
      setTimeout(() =>
        effects.forEach(([fn, ...args]) => fn(store.dispatch, ...args)), 0);
    }
  };

  store = createStore(enhanceReducer(rootReducer, deferEffects), initialState);

  return {
    ...store,
    replaceReducer: nextReducer => {
      replacing = true;
      store.replaceReducer(enhanceReducer(nextReducer, deferEffects));
      replacing = false;
    }
  };
};<commit_msg>dispatching from external store (like devtools) should not execute effects<commit_after>import enhanceReducer from './enhanceReducer';

/**
 * Creates enhanced store factory, which takes original `createStore` as argument.
 * Returns modified store which is capable of handling Reducers in form of Generators.
 *
 * @param {Function} Original createStore implementation to be enhanced
 * @returns {Function} Store factory
 */
export default createStore => (rootReducer, initialState) => {
  let store = null;
  let dispatching = false;
  let wrappedDispatch = null;

  const deferEffects = effects => {
    if (dispatching) {
      setTimeout(() =>
        effects.forEach(([fn, ...args]) => fn(wrappedDispatch, ...args)), 0);
    }
  };

  // it is expected that createStore will do one dispatch before we wrap it
  dispatching = true;
  store = createStore(enhanceReducer(rootReducer, deferEffects), initialState);
  dispatching = false;

  wrappedDispatch = (...args) => {
    dispatching = true;
    const result = store.dispatch(...args);
    dispatching = false;
    return result;
  };

  return {
    ...store,
    dispatch: wrappedDispatch,
    replaceReducer: nextReducer => {
      store.replaceReducer(enhanceReducer(nextReducer, deferEffects));
    }
  };
};
{'fraction_non_alphanumeric': 0.11684162482884528, 'fraction_numerical': 0.0009128251939753537, 'mean_word_length': 3.653927813163482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '6251873', 'n_tokens_mistral': 628, 'n_tokens_neox': 596, 'n_words': 188}