<commit_before>import PropTypes from 'prop-types'
import { createStructuredSelector } from 'reselect'

import { safePathSelector } from './selectors'
import { addReducer } from '../scene/store'

export function createPropTransforms (mapping = []) {
  if (mapping.length % 2 === 1) {
    console.error('[KEA-LOGIC] uneven mapping given to selectPropsFromLogic:', mapping)
    console.trace()
    return
  }

  let hash = {}
  let transforms = {}

  for (let i = 0; i < mapping.length; i += 2) {
    let logic = mapping[i]
    const props = mapping[i + 1]

    // we were given a function (state) => state.something as logic input
    let isFunction = (typeof logic === 'function') && !logic._isKeaFunction

    // path selector array
    if (Array.isArray(logic)) {
      logic = state => safePathSelector(mapping[i], state)
      isFunction = true
    }

    if (logic._isKeaSingleton) {
      if (!logic._keaReducerConnected) {
        addReducer(logic.path, logic.reducer, true)
        logic._keaReducerConnected = true
      }
    }

    const selectors = isFunction ? null : (logic.selectors ? logic.selectors : logic)

    props.forEach(query => {
      let from = query
      let to = query

      if (query.includes(' as ')) {
        [from, to] = query.split(' as ')
      }

      const matches = from.match(/^(.*)\[(.*)\]$/)

      if (matches) {
        if (from === to) {
          to = matches[1]
        }
        from = matches[1]
        transforms[to] = (value, props) => {
          return value[props[matches[2]]]
        }
      }

      if (from === '*') {
        hash[to] = isFunction ? logic : (logic.selector ? logic.selector : selectors)
      } else if (isFunction) {
        hash[to] = (state) => (logic(state) || {})[from]
      } else if (typeof selectors[from] !== 'undefined') {
        hash[to] = selectors[from]
      } else {
        console.error(`[KEA-LOGIC] selector "${query}" missing for logic:`, logic)
        console.trace()
      }
    })
  }

  return {
    selectorFunctions: hash,
    selectors: createStructuredSelector(hash),
    transforms: transforms
  }
}

export function selectPropsFromLogic (mapping = []) {
  return createPropTransforms(mapping).selectors
}

export function propTypesFromMapping (mapping, extra = null) {
  let propTypes = Object.assign({}, mapping.propTypes || mapping.passedProps || {})

  if (mapping.props) {
    if (mapping.props.length % 2 === 1) {
      console.error('[KEA-LOGIC] uneven props mapping given to propTypesFromLogic:', mapping)
      console.trace()
      return
    }
    for (let i = 0; i < mapping.props.length; i += 2) {
      let logic = mapping.props[i]
      const props = mapping.props[i + 1]

      if (logic._isKeaSingleton) {
        if (!logic._keaReducerConnected) {
          addReducer(logic.path, logic.reducer, true)
          logic._keaReducerConnected = true
        }
      }

      if (logic && logic.reducers) {
        props.forEach(query => {
          let from = query
          let to = query

          if (query.includes(' as ')) {
            [from, to] = query.split(' as ')
          }

          const matches = from.match(/^(.*)\[(.*)]$/)

          if (matches) {
            if (from === to) {
              to = matches[1]
            }
            from = matches[1]
          }

          const reducer = logic.reducers[from]

          if (reducer && reducer.type) {
            propTypes[to] = reducer.type
          } else {
            console.error(`[KEA-LOGIC] prop type "${query}" missing for logic:`, logic)
            console.trace()
          }
        })
      }
    }
  }

  if (mapping.actions) {
    if (mapping.actions.length % 2 === 1) {<commit_msg>prop type not important for *<commit_after>import PropTypes from 'prop-types'
import { createStructuredSelector } from 'reselect'

import { safePathSelector } from './selectors'
import { addReducer } from '../scene/store'

export function createPropTransforms (mapping = []) {
  if (mapping.length % 2 === 1) {
    console.error('[KEA-LOGIC] uneven mapping given to selectPropsFromLogic:', mapping)
    console.trace()
    return
  }

  let hash = {}
  let transforms = {}

  for (let i = 0; i < mapping.length; i += 2) {
    let logic = mapping[i]
    const props = mapping[i + 1]

    // we were given a function (state) => state.something as logic input
    let isFunction = (typeof logic === 'function') && !logic._isKeaFunction

    // path selector array
    if (Array.isArray(logic)) {
      logic = state => safePathSelector(mapping[i], state)
      isFunction = true
    }

    if (logic._isKeaSingleton) {
      if (!logic._keaReducerConnected) {
        addReducer(logic.path, logic.reducer, true)
        logic._keaReducerConnected = true
      }
    }

    const selectors = isFunction ? null : (logic.selectors ? logic.selectors : logic)

    props.forEach(query => {
      let from = query
      let to = query

      if (query.includes(' as ')) {
        [from, to] = query.split(' as ')
      }

      const matches = from.match(/^(.*)\[(.*)\]$/)

      if (matches) {
        if (from === to) {
          to = matches[1]
        }
        from = matches[1]
        transforms[to] = (value, props) => {
          return value[props[matches[2]]]
        }
      }

      if (from === '*') {
        hash[to] = isFunction ? logic : (logic.selector ? logic.selector : selectors)
      } else if (isFunction) {
        hash[to] = (state) => (logic(state) || {})[from]
      } else if (typeof selectors[from] !== 'undefined') {
        hash[to] = selectors[from]
      } else {
        console.error(`[KEA-LOGIC] selector "${query}" missing for logic:`, logic)
        console.trace()
      }
    })
  }

  return {
    selectorFunctions: hash,
    selectors: createStructuredSelector(hash),
    transforms: transforms
  }
}

export function selectPropsFromLogic (mapping = []) {
  return createPropTransforms(mapping).selectors
}

export function propTypesFromMapping (mapping, extra = null) {
  let propTypes = Object.assign({}, mapping.propTypes || mapping.passedProps || {})

  if (mapping.props) {
    if (mapping.props.length % 2 === 1) {
      console.error('[KEA-LOGIC] uneven props mapping given to propTypesFromLogic:', mapping)
      console.trace()
      return
    }
    for (let i = 0; i < mapping.props.length; i += 2) {
      let logic = mapping.props[i]
      const props = mapping.props[i + 1]

      if (logic._isKeaSingleton) {
        if (!logic._keaReducerConnected) {
          addReducer(logic.path, logic.reducer, true)
          logic._keaReducerConnected = true
        }
      }

      if (logic && logic.reducers) {
        props.forEach(query => {
          let from = query
          let to = query

          if (query.includes(' as ')) {
            [from, to] = query.split(' as ')
          }

          const matches = from.match(/^(.*)\[(.*)]$/)

          if (matches) {
            if (from === to) {
              to = matches[1]
            }
            from = matches[1]
          }

          const reducer = logic.reducers[from]

          if (reducer && reducer.type) {
            propTypes[to] = reducer.type
          } else if (from !== '*') {
            console.error(`[KEA-LOGIC] prop type for "${from}" missing for logic:`, logic)
            console.trace()
          }
        })
      }
    }
  }

  if (mapping.actions) {
    if (mapping.actions.length % 2 === 1) {
{'fraction_non_alphanumeric': 0.14247275662585765, 'fraction_numerical': 0.004574196152293825, 'mean_word_length': 2.1327433628318584, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '5141282', 'n_tokens_mistral': 2370, 'n_tokens_neox': 2248, 'n_words': 556}