<commit_before>/* eslint no-underscore-dangle: 0 */
import { applyMiddleware, createStore as _createStore, Middleware, Reducer, Store, StoreCreator } from 'redux'
import { Config, Model } from '../../typings/rematch'
import { pluginMiddlewares } from '../core'
import { composeEnhancers } from './devtools'
import { createModelReducer, createRootReducer, mergeReducers } from './reducers'

export let store: Store<any>
let rootReducers

export const initStore = ({ redux }: Config): Store<any> => {
  const initialState: any = typeof redux.initialState === 'undefined' ? {} : redux.initialState
  const createStore: StoreCreator = redux.createStore || _createStore
  rootReducers = redux.rootReducers
  const rootReducer: Reducer<any> = createRootReducer(rootReducers)
  const middlewareList: Middleware[] = [...pluginMiddlewares, ...(redux.middlewares || [])]
  const middlewares = applyMiddleware(...middlewareList)
  const enhancers = [redux.devtoolOptions, ...(redux.enhancers || [])]
  const composedEnhancers = composeEnhancers(...enhancers)(middlewares)
  store = createStore(rootReducer, initialState, composedEnhancers)
  return store
}

// allows for "model" to dynamically update the reducers/store
export const createReducersAndUpdateStore = (model: Model): void => {
  mergeReducers(createModelReducer(model))
  store.replaceReducer(createRootReducer(rootReducers))
}<commit_msg>fix issue with enhancers<commit_after>/* eslint no-underscore-dangle: 0 */
import { applyMiddleware, createStore as _createStore, Middleware, Reducer, Store, StoreCreator } from 'redux'
import { Config, Model } from '../../typings/rematch'
import { pluginMiddlewares } from '../core'
import { composeEnhancers } from './devtools'
import { createModelReducer, createRootReducer, mergeReducers } from './reducers'

export let store: Store<any>
let rootReducers

export const initStore = ({ redux }: Config): Store<any> => {
  const initialState: any = typeof redux.initialState === 'undefined' ? {} : redux.initialState
  const createStore: StoreCreator = redux.createStore || _createStore
  rootReducers = redux.rootReducers
  const rootReducer: Reducer<any> = createRootReducer(rootReducers)
  const middlewareList: Middleware[] = [...pluginMiddlewares, ...(redux.middlewares || [])]
  const middlewares = applyMiddleware(...middlewareList)
  const enhancers = composeEnhancers(redux.devtoolOptions)(...redux.enhancers || [], middlewares)
  store = createStore(rootReducer, initialState, enhancers)
  return store
}

// allows for "model" to dynamically update the reducers/store
export const createReducersAndUpdateStore = (model: Model): void => {
  mergeReducers(createModelReducer(model))
  store.replaceReducer(createRootReducer(rootReducers))
}
{'fraction_non_alphanumeric': 0.12180889861415026, 'fraction_numerical': 0.0007293946024799417, 'mean_word_length': 5.577937649880096, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '1311741', 'n_tokens_mistral': 855, 'n_tokens_neox': 825, 'n_words': 202}