<commit_before>const RESERVED_PROPS = new Set(['on', 'ref'])

export default function updateProps(domNode, oldVirtualNode, newVirtualNode, options) {
  const oldProps = oldVirtualNode && oldVirtualNode.props
  const newProps = newVirtualNode.props

  let refs, listenerContext
  if (options) {
    refs = options.refs
    listenerContext = options.listenerContext
  }
  updateAttributes(domNode, oldProps, newProps)
  if (refs) updateRef(domNode, oldProps && oldProps.ref, newProps && newProps.ref, refs)
  updateEventListeners(domNode, oldVirtualNode, newVirtualNode, listenerContext)
}

function updateAttributes (domNode, oldProps, newProps) {
  for (const name in oldProps) {
    if (RESERVED_PROPS.has(name)) continue
    if (!newProps || !(name in newProps)) {
      domNode.removeAttribute(name)
    }
  }
  for (let name in newProps) {
    if (RESERVED_PROPS.has(name)) continue
    const oldValue = oldProps && oldProps[name]
    const newValue = newProps[name]
    if (newValue !== oldValue) {
      domNode.setAttribute(name, newValue)
    }
  }
}

function updateRef (domNode, oldRefName, newRefName, refs) {
  if (newRefName !== oldRefName) {
    if (oldRefName && refs[oldRefName] === domNode) delete refs[oldRefName]
    if (newRefName) refs[newRefName] = domNode
  }
}

function updateEventListeners (domNode, oldVirtualNode, newVirtualNode, listenerContext) {
  const oldListeners = oldVirtualNode && oldVirtualNode.props && oldVirtualNode.props.on
  const newListeners = newVirtualNode.props && newVirtualNode.props.on

  for (const name in oldListeners) {
    if (!(newListeners && name in newListeners)) {
      let listenerToRemove
      if (oldVirtualNode && oldVirtualNode.boundListeners && oldVirtualNode.boundListeners[name]) {
        listenerToRemove = oldVirtualNode.boundListeners[name]
      } else {
        listenerToRemove =oldListeners[name]
      }
      domNode.removeEventListener(name, listenerToRemove)
    }
  }

  for (const name in newListeners) {
    const oldListener = oldListeners && oldListeners[name]
    const newListener = newListeners[name]

    if (newListener !== oldListener) {
      if (oldListener) {
        let listenerToRemove
        if (oldVirtualNode && oldVirtualNode.boundListeners && oldVirtualNode.boundListeners[name]) {
          listenerToRemove = oldVirtualNode.boundListeners[name]
        } else {
          listenerToRemove = oldListener
        }
        domNode.removeEventListener(name, listenerToRemove)
      }
      let listenerToAdd
      if (listenerContext) {
        listenerToAdd = newListener.bind(listenerContext)
        if (!newVirtualNode.boundListeners) newVirtualNode.boundListeners = {}
        newVirtualNode.boundListeners[name] = listenerToAdd
      } else {
        listenerToAdd = newListener
      }
      domNode.addEventListener(name, listenerToAdd)
    }
  }
}<commit_msg>:art:<commit_after>const RESERVED_PROPS = new Set(['on', 'ref'])

export default function updateProps(domNode, oldVirtualNode, newVirtualNode, options) {
  const oldProps = oldVirtualNode && oldVirtualNode.props
  const newProps = newVirtualNode.props

  let refs, listenerContext
  if (options) {
    refs = options.refs
    listenerContext = options.listenerContext
  }
  updateAttributes(domNode, oldProps, newProps)
  if (refs) updateRef(domNode, oldProps && oldProps.ref, newProps && newProps.ref, refs)
  updateEventListeners(domNode, oldVirtualNode, newVirtualNode, listenerContext)
}

function updateAttributes (domNode, oldProps, newProps) {
  for (const name in oldProps) {
    if (RESERVED_PROPS.has(name)) continue
    if (!newProps || !(name in newProps)) {
      domNode.removeAttribute(name)
    }
  }
  for (let name in newProps) {
    if (RESERVED_PROPS.has(name)) continue
    const oldValue = oldProps && oldProps[name]
    const newValue = newProps[name]
    if (newValue !== oldValue) {
      domNode.setAttribute(name, newValue)
    }
  }
}

function updateRef (domNode, oldRefName, newRefName, refs) {
  if (newRefName !== oldRefName) {
    if (oldRefName && refs[oldRefName] === domNode) delete refs[oldRefName]
    if (newRefName) refs[newRefName] = domNode
  }
}

function updateEventListeners (domNode, oldVirtualNode, newVirtualNode, listenerContext) {
  const oldListeners = oldVirtualNode && oldVirtualNode.props && oldVirtualNode.props.on
  const newListeners = newVirtualNode.props && newVirtualNode.props.on

  for (const eventName in oldListeners) {
    if (!(newListeners && eventName in newListeners)) {
      let listenerToRemove
      if (oldVirtualNode && oldVirtualNode.boundListeners && oldVirtualNode.boundListeners[eventName]) {
        listenerToRemove = oldVirtualNode.boundListeners[eventName]
      } else {
        listenerToRemove =oldListeners[eventName]
      }
      domNode.removeEventListener(eventName, listenerToRemove)
    }
  }

  for (const eventName in newListeners) {
    const oldListener = oldListeners && oldListeners[eventName]
    const newListener = newListeners[eventName]

    if (newListener !== oldListener) {
      if (oldListener) {
        let listenerToRemove
        if (oldVirtualNode && oldVirtualNode.boundListeners && oldVirtualNode.boundListeners[eventName]) {
          listenerToRemove = oldVirtualNode.boundListeners[eventName]
        } else {
          listenerToRemove = oldListener
        }
        domNode.removeEventListener(eventName, listenerToRemove)
      }
      let listenerToAdd
      if (listenerContext) {
        listenerToAdd = newListener.bind(listenerContext)
        if (!newVirtualNode.boundListeners) newVirtualNode.boundListeners = {}
        newVirtualNode.boundListeners[eventName] = listenerToAdd
      } else {
        listenerToAdd = newListener
      }
      domNode.addEventListener(eventName, listenerToAdd)
    }
  }
}
{'fraction_non_alphanumeric': 0.09504132231404959, 'fraction_numerical': 0.0, 'mean_word_length': 3.7889530090684254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5283130', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1698, 'n_words': 370}