<commit_before>
/**
 * Create a patch function from a diff.
 *
 * @param {Mount} mount The mounted component
 * @param {Node} next The updated node representation
 * @api public
 */

module.exports = function(mount, next) {
  diff(mount, mount.component.current, next, mount.el);
}

/**
 * Create a diff between two tress of nodes.
 */

function diff(mount, current, next, el) {

  // Node type changed
  if (current.type !== next.type) {
    mount.removeComponents(current);
    var newEl = mount.toElement(next); // TODO create child components
    el.parentNode.replaceChild(newEl, el);
    return;
  }

  // update the text content.
  if (next.type === 'text') {
    if (next.data !== current.data) {
      el.data = next.data;
    }
    return;
  }

  // if they are both components.
  if (next.type === 'component') {
    var child = mount.getChildByNode(current);
    child.set(next.props);
    // TODO when we add batching this will need to call
    // .render on the component so it updates immediately
    return;
  }

  // if they are both elements.
  if (next.type === 'element') {

    // different node, so swap them.
    // TODO update this so it creates a new element and just moves the attributes
    // and the child nodes over to the new node and swaps them out
    if (next.tagName !== current.tagName) {
      mount.removeComponents(current);
      var newEl = mount.toElement(next);
      el.parentNode.replaceChild(newEl, el);<commit_msg>Updated comments<commit_after>
/**
 * Create a patch function from a diff.
 *
 * @param {Mount} mount The mounted component
 * @param {Node} next The updated node representation
 * @api public
 */

module.exports = function(mount, next) {
  diff(mount, mount.component.current, next, mount.el);
}

/**
 * Create a diff between two tress of nodes.
 */

function diff(mount, current, next, el) {

  // Type changed. This could be from element->text, text->ComponentA,
  // ComponentA->ComponentB etc. But NOT div->span. These are the same type
  // (ElementNode) but different tag name.
  if (current.type !== next.type) {
    mount.removeComponents(current);
    var newEl = mount.toElement(next);
    el.parentNode.replaceChild(newEl, el);
    return;
  }

  // update the text content.
  if (next.type === 'text') {
    if (next.data !== current.data) {
      el.data = next.data;
    }
    return;
  }

  // if they are both components.
  if (next.type === 'component') {
    var child = mount.getChildByNode(current);
    child.set(next.props);
    // TODO when we add batching this will need to call
    // .render on the component so it updates immediately
    return;
  }

  // if they are both elements.
  if (next.type === 'element') {

    // different node, so swap them.
    // TODO update this so it creates a new element and just moves the attributes
    // and the child nodes over to the new node and swaps them out
    if (next.tagName !== current.tagName) {
      mount.removeComponents(current);
      var newEl = mount.toElement(next);
      el.parentNode.replaceChild(newEl, el);
{'fraction_non_alphanumeric': 0.12222222222222222, 'fraction_numerical': 0.0, 'mean_word_length': 2.850314465408805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2082179', 'n_tokens_mistral': 913, 'n_tokens_neox': 906, 'n_words': 322}