<commit_before>/* @flow */
import objectReduce from 'fast-loops/lib/objectReduce'
import objectEach from 'fast-loops/lib/objectEach'
import { combineMultiRules } from 'fela-tools'
import shallowCompare from 'react-addons-shallow-compare'

import generateDisplayName from './generateDisplayName'
import hoistStatics from './hoistStatics'

export type ConnectConfig = {
  pure?: boolean
}

const defaultConfig: ConnectConfig = {
  pure: true
}

export default function connectFactory(
  BaseComponent: any,
  createElement: Function,
  withTheme: Function,
  contextTypes?: Object
): Function {
  return function connect(rules: Object | Function, config: ConnectConfig = {}): Function {
    const connectConfig = {
      ...defaultConfig,
      ...config,
    }

    return (component: any): any => {
      class EnhancedComponent extends BaseComponent {
        static displayName = generateDisplayName(component)
        static _isFelaComponent = true

        shouldComponentUpdate(nextProps, nextState) {
          if (connectConfig.pure) {
            return shallowCompare(this, nextProps, nextState)
          }
          return true
        }

        render() {
          const { renderer } = this.context
          const { extend, _felaTheme, _felaRules, ...otherProps } = this.props

          const allRules = [rules]
          if (_felaRules) {
            allRules.push(_felaRules)
          }
          if (extend) {
            allRules.push(extend)
          }

          const combinedRules = combineMultiRules(...allRules)<commit_msg>fela connect pure component formatting<commit_after>/* @flow */
import objectReduce from 'fast-loops/lib/objectReduce'
import objectEach from 'fast-loops/lib/objectEach'
import { combineMultiRules } from 'fela-tools'
import shallowCompare from 'react-addons-shallow-compare'

import generateDisplayName from './generateDisplayName'
import hoistStatics from './hoistStatics'

export type ConnectConfig = {
  pure?: boolean,
}

const defaultConfig: ConnectConfig = {
  pure: true,
}

export default function connectFactory(
  BaseComponent: any,
  createElement: Function,
  withTheme: Function,
  contextTypes?: Object
): Function {
  return function connect(
    rules: Object | Function,
    config: ConnectConfig = {}
  ): Function {
    const connectConfig = {
      ...defaultConfig,
      ...config,
    }

    return (component: any): any => {
      class EnhancedComponent extends BaseComponent {
        static displayName = generateDisplayName(component)
        static _isFelaComponent = true

        shouldComponentUpdate(nextProps, nextState) {
          if (connectConfig.pure) {
            return shallowCompare(this, nextProps, nextState)
          }
          return true
        }

        render() {
          const { renderer } = this.context
          const { extend, _felaTheme, _felaRules, ...otherProps } = this.props

          const allRules = [rules]
          if (_felaRules) {
            allRules.push(_felaRules)
          }
          if (extend) {
            allRules.push(extend)
          }

          const combinedRules = combineMultiRules(...allRules)
{'fraction_non_alphanumeric': 0.0936007640878701, 'fraction_numerical': 0.0, 'mean_word_length': 2.683470105509965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7381789', 'n_tokens_mistral': 847, 'n_tokens_neox': 828, 'n_words': 218}