<commit_before>import { REHYDRATE } from './constants'
import isStatePlainEnough from './utils/isStatePlainEnough'

export default function autoRehydrate (config = {}) {
  return (next) => (reducer, initialState, enhancer) => {
    return next(createRehydrationReducer(reducer), initialState, enhancer)
  }

  function createRehydrationReducer (reducer) {
    let rehydrated = false
    let preRehydrateActions = []
    return (state, action) => {
      if (action.type !== REHYDRATE) {
        if (config.log && !rehydrated) preRehydrateActions.push(action) // store pre-rehydrate actions for debugging
        return reducer(state, action)
      } else {
        if (config.log && !rehydrated) logPreRehydrate(preRehydrateActions)
        rehydrated = true

        let inboundState = action.payload
        let reducedState = reducer(state, action)
        let newState = {...reducedState}

        Object.keys(inboundState).forEach((key) => {
          // if initialState does not have key, skip auto rehydration
          if (!state.hasOwnProperty(key)) return

          // if reducer modifies substate, skip auto rehydration
          if (state[key] !== reducedState[key]) {
            if (config.log) console.log('redux-persist/autoRehydrate: sub state for key `%s` modified, skipping autoRehydrate.', key)
            newState[key] = reducedState[key]
            return
          }

          // otherwise take the inboundState
          if (isStatePlainEnough(inboundState[key]) && isStatePlainEnough(reducedState[key])) newState[key] = {...state[key], ...inboundState[key]} // shallow merge
          else newState[key] = inboundState[key] // hard set

          if (config.log) console.log('redux-persist/autoRehydrate: key `%s`, rehydrated to ', key, newState[key])
        })
        return newState
      }
    }
  }
}<commit_msg>Fix typo in autoRehydrate.js (#103)<commit_after>import { REHYDRATE } from './constants'
import isStatePlainEnough from './utils/isStatePlainEnough'

export default function autoRehydrate (config = {}) {
  return (next) => (reducer, initialState, enhancer) => {
    return next(createRehydrationReducer(reducer), initialState, enhancer)
  }

  function createRehydrationReducer (reducer) {
    let rehydrated = false
    let preRehydrateActions = []
    return (state, action) => {
      if (action.type !== REHYDRATE) {
        if (config.log && !rehydrated) preRehydrateActions.push(action) // store pre-rehydrate actions for debugging
        return reducer(state, action)
      } else {
        if (config.log && !rehydrated) logPreRehydrate(preRehydrateActions)
        rehydrated = true

        let inboundState = action.payload
        let reducedState = reducer(state, action)
        let newState = {...reducedState}

        Object.keys(inboundState).forEach((key) => {
          // if initialState does not have key, skip auto rehydration
          if (!state.hasOwnProperty(key)) return

          // if reducer modifies substate, skip auto rehydration
          if (state[key] !== reducedState[key]) {
            if (config.log) console.log('redux-persist/autoRehydrate: sub state for key `%s` modified, skipping autoRehydrate.', key)
            newState[key] = reducedState[key]
            return
          }

          // otherwise take the inboundState
          if (isStatePlainEnough(inboundState[key]) && isStatePlainEnough(state[key])) newState[key] = {...state[key], ...inboundState[key]} // shallow merge
          else newState[key] = inboundState[key] // hard set

          if (config.log) console.log('redux-persist/autoRehydrate: key `%s`, rehydrated to ', key, newState[key])
        })
        return newState
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.11701267187921273, 'fraction_numerical': 0.0008088433540037746, 'mean_word_length': 2.8485477178423237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1030561', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1079, 'n_words': 266}