<commit_before>import {Fixture} from './fixture'
import {Scene} from './scene'
import _ from 'lodash'

let renderTree = {}
let newRenderTree = {}
let nextMountId = 1
let parentNextMountId = null
let currentId = ''

class ReactElement {
  static create(type, config, ...children) {
    let props = {}

    let key = null
    let ref = null

    if (config != null) {
      ref = config.ref === undefined ? null : config.ref
      key = config.key === undefined ? null : '' + config.key

      // add remaining props
      for (let propName in config) {
        if (config.hasOwnProperty(propName)) props[propName] = config[propName]
      }
    }

    // Children can be more than one argument, and those are transferred onto
    // the newly allocated props object.
    let childrenLength = arguments.length - 2
    if (childrenLength === 1) {
      props.children = children
    } else if (childrenLength > 1) {
      var childArray = Array(childrenLength)
      for (var i = 0; i < childrenLength; i++) {
        childArray[i] = arguments[i + 2]
      }
      props.children = childArray
    }

    // Resolve default props
    if (type && type.defaultProps) {
      let defaultProps = type.defaultProps
      for (let propName in defaultProps) {
        if (typeof props[propName] === 'undefined') {
          props[propName] = defaultProps[propName]
        }
      }
    }

    return new ReactElement(
      type,
      key,
      ref,
      null,
      props
    )
  }

  constructor(type, key, ref, owner, props) {
    // Built-in properties that belong on the element
    this.type = type
    this.key = key
    this.ref = ref

    // Record the component responsible for creating this element.
    this._owner = owner

    this.props = props
  }
}

export var React = {
  createElement: ReactElement.create,

  render(element, context) {
    nextMountId = 1
    currentId = ''
    newRenderTree = {}

    React._render(null, element, context)

    // look at new render tree and unmount old components
    let oldIds = _.difference(_.keys(renderTree), _.keys(newRenderTree))

    // unmount old ids
    for (let oldId of oldIds) {
      let component = renderTree[oldId]
      component.unmount()

      delete renderTree[oldId]
    }
  },

  _render(parentComponent, element, context) {
    if (!element) {
      throw new Error('No element provided!')
    }

    let key = ''

    if (element.key) key = `$${element.key}`

    let thisId = `${currentId}.${element.type.name}${key}$${nextMountId++}`

    let component = null

    if (renderTree[thisId]) {
      component = newRenderTree[thisId] = renderTree[thisId]

      // props changed?
      if (!_.isEqual(component.props, element.props)) {<commit_msg>handle different component classes with same id in render tree<commit_after>import {Fixture} from './fixture'
import {Scene} from './scene'
import _ from 'lodash'

let renderTree = {}
let newRenderTree = {}
let nextMountId = 1
let parentNextMountId = null
let currentId = ''

class ReactElement {
  static create(type, config, ...children) {
    let props = {}

    let key = null
    let ref = null

    if (config != null) {
      ref = config.ref === undefined ? null : config.ref
      key = config.key === undefined ? null : '' + config.key

      // add remaining props
      for (let propName in config) {
        if (config.hasOwnProperty(propName)) props[propName] = config[propName]
      }
    }

    // Children can be more than one argument, and those are transferred onto
    // the newly allocated props object.
    let childrenLength = arguments.length - 2
    if (childrenLength === 1) {
      props.children = children
    } else if (childrenLength > 1) {
      var childArray = Array(childrenLength)
      for (var i = 0; i < childrenLength; i++) {
        childArray[i] = arguments[i + 2]
      }
      props.children = childArray
    }

    // Resolve default props
    if (type && type.defaultProps) {
      let defaultProps = type.defaultProps
      for (let propName in defaultProps) {
        if (typeof props[propName] === 'undefined') {
          props[propName] = defaultProps[propName]
        }
      }
    }

    return new ReactElement(
      type,
      key,
      ref,
      null,
      props
    )
  }

  constructor(type, key, ref, owner, props) {
    // Built-in properties that belong on the element
    this.type = type
    this.key = key
    this.ref = ref

    // Record the component responsible for creating this element.
    this._owner = owner

    this.props = props
  }
}

export var React = {
  createElement: ReactElement.create,

  render(element, context) {
    nextMountId = 1
    currentId = ''
    newRenderTree = {}

    React._render(null, element, context)

    // look at new render tree and unmount old components
    let oldIds = _.difference(_.keys(renderTree), _.keys(newRenderTree))

    // unmount old ids
    for (let oldId of oldIds) {
      let component = renderTree[oldId]
      component.unmount()

      delete renderTree[oldId]
    }
  },

  _render(parentComponent, element, context) {
    if (!element) {
      throw new Error('No element provided!')
    }

    let key = ''

    if (element.key) key = `$${element.key}`

    let thisId = `${currentId}.${element.type.name}${key}$${nextMountId++}`

    let component = null

    if (renderTree[thisId] && element.type !== renderTree[thisId].constructor) {
      // ID already exists in render tree, but the component class is wrong
      renderTree[thisId].unmount()
      delete renderTree[thisId]
    }

    if (renderTree[thisId]) {
      component = newRenderTree[thisId] = renderTree[thisId]

      // props changed?
      if (!_.isEqual(component.props, element.props)) {
{'fraction_non_alphanumeric': 0.11447046487242223, 'fraction_numerical': 0.002446696959105208, 'mean_word_length': 2.498166259168704, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3893442', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1662, 'n_words': 504}