<commit_before>import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'

import { shallowEquals, isObject } from './utils/helpers'
import bindActionCreators from './utils/bindActionCreators'
import { getContextTypes } from './contextTypes'

const initAction = {
  type: '@@localReducer/INIT'
}

const defaultOptions = {
  listenToStoreActions: true
}

const identity = args => args

const withReducer = (
  createReducer,
  mapDispatchToProps,
  options
) => WrappedComponent => {
  class WithReducer extends PureComponent {
    constructor(props, context) {
      super(props, context)

      this.mapToProps = options.mapToProps || identity
      this.reducer = createReducer(props, context)
      this.state = this.reducer(undefined, initAction)
      this.actionCreators = bindActionCreators(
        mapDispatchToProps,
        this.dispatchAction,
        this.props
      )

      const { store } = context
      const finalOptions = { ...defaultOptions, ...options }

      if (store && store.onDispatch) {
        if (finalOptions.listenToStoreActions) {
          this.unsubscribe = store.onDispatch(this.dispatchAction)
        }
      }
    }

    dispatchAction = action => {
      if (!isObject(action) || !action.type) {
        console.error(
          `[${componentName}][dispatch] Expected an action object with type, got:`,
          action
        )
        return
      }

      const newState = this.reducer(this.state, action)

      if (!isObject(newState)) {
        console.error(
          `[${componentName}][reducer] Expected an object to be returned, got:`,
          newState
        )
      }

      if (!shallowEquals(this.state, newState)) {
        this.setState(newState)
      }
    }

    componentWillUnmount() {
      if (this.unsubscribe) {
        this.unsubscribe()
      }
    }

    render() {
      return React.createElement(WrappedComponent, {
        ...this.props,
        ...(this.mapToProps({
          ...this.state,
          ...this.actionCreators,
        }))
      })
    }
  }

  WithReducer.contextTypes = {
    store: PropTypes.object,
    ...getContextTypes()
  }

  return WithReducer
}

export default withReducer<commit_msg>refactor: pass state and actionCreators separately<commit_after>import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'

import { shallowEquals, isObject } from './utils/helpers'
import bindActionCreators from './utils/bindActionCreators'
import { getContextTypes } from './contextTypes'

const initAction = {
  type: '@@localReducer/INIT'
}

const defaultOptions = {
  listenToStoreActions: true
}

const merge = (...args) => Object.assign({}, ...args)

const withReducer = (
  createReducer,
  mapDispatchToProps,
  options
) => WrappedComponent => {
  class WithReducer extends PureComponent {
    constructor(props, context) {
      super(props, context)

      this.mapToProps = options.mapToProps || merge
      this.reducer = createReducer(props, context)
      this.state = this.reducer(undefined, initAction)
      this.actionCreators = bindActionCreators(
        mapDispatchToProps,
        this.dispatchAction,
        this.props
      )

      const { store } = context
      const finalOptions = { ...defaultOptions, ...options }

      if (store && store.onDispatch) {
        if (finalOptions.listenToStoreActions) {
          this.unsubscribe = store.onDispatch(this.dispatchAction)
        }
      }
    }

    dispatchAction = action => {
      if (!isObject(action) || !action.type) {
        console.error(
          `[${componentName}][dispatch] Expected an action object with type, got:`,
          action
        )
        return
      }

      const newState = this.reducer(this.state, action)

      if (!isObject(newState)) {
        console.error(
          `[${componentName}][reducer] Expected an object to be returned, got:`,
          newState
        )
      }

      if (!shallowEquals(this.state, newState)) {
        this.setState(newState)
      }
    }

    componentWillUnmount() {
      if (this.unsubscribe) {
        this.unsubscribe()
      }
    }

    render() {
      return React.createElement(WrappedComponent, {
        ...this.props,
        ...this.mapToProps(this.state, this.actionCreators)
      })
    }
  }

  WithReducer.contextTypes = {
    store: PropTypes.object,
    ...getContextTypes()
  }

  return WithReducer
}

export default withReducer
{'fraction_non_alphanumeric': 0.11444018923180897, 'fraction_numerical': 0.0, 'mean_word_length': 2.457943925233645, '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': '1956424', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1273, 'n_words': 268}