<commit_before>'use strict';

const VirtualDOMNode = require('../virtualDOMNode');

class VirtualDOMElement extends VirtualDOMNode {
  constructor(tagName, props) {
    const domElement = document.createElement(tagName);

    super(props, domElement);
  }

  mount(parent, reference, context) {
    super.mount(parent, reference);

    const childParent = this,
          childReference = null,
          childContext = context;

    this.children.forEach(function(child) {
      child.mount(childParent, childReference, childContext);
    });

    this.applyProps();
  }

  unmount(context) {
    const childContext = context;

    this.children.forEach(function(child) {
      child.unmount(childContext);
    });

    super.unmount();
  }

  getTagName() {
    const domElement = this.getDOMElement(),
          tagName = domElement.tagName; 

    return tagName;
  }

  spliceChildren(start, removedChildrenCount, addedChildren, context) {
    const childParent = this,
          childReference = null,
          childContext = context;

    addedChildren.forEach(function(addedChild) {
      addedChild.mount(childParent, childReference, childContext);
    });

    const args = [start, removedChildrenCount].concat(addedChildren),
          removedChildren = Array.prototype.splice.apply(this.children, args);

    removedChildren.forEach(function(removedChild) {
      removedChild.unmount(childContext);
    });
  }

  addChild(child, context) {
    const start = Infinity,
          removedChildrenCount = 0,
          addedChildren = [child];

    this.spliceChildren(start, removedChildrenCount, addedChildren, context);
  }

  removeChild(child, context) {
    const index = this.children.indexOf(child);

    if (index > -1) {
      const start = index,
            removedChildrenCount = 1,
            addedChildren = [];

      this.spliceChildren(start, removedChildrenCount, addedChildren, context);
    }
  }
  
  setAttribute(name, value) {
    if (name === 'className') {
      name = 'class';
    }
    
    if (name === 'htmlFor') {
      name = 'for';
    }

    if (false) {

    } else if (typeof value === 'object') {
      const keys = Object.keys(value);

      keys.forEach(function (key) {
        this.domElement[name][key] = value[key];
      }.bind(this));
    } else if (typeof value === 'boolean') {
      if (value) {
        value = name; ///

        this.domElement.setAttribute(name, value);
      }
    } else {
      this.domElement.setAttribute(name, value);
    }
  }

  getAttribute(name) {
    return this.domElement.getAttribute(name);
  }

  clearAttribute(name) {
    this.domElement.removeAttribute(name);
  }

  setClass(className) {
    this.domElement.className = className;
  }

  addClass(className) {
    this.domElement.classList.add(className);
  }

  removeClass(className) {
    this.domElement.classList.remove(className);
  }

  toggleClass(className) {
    this.domElement.classList.toggle(className);
  }

  hasClass(className) {
    return this.domElement.classList.contains(className);
  }

  clearClasses() {
    this.domElement.className = '';
  }

  applyProps() {<commit_msg>Cosmetic changes to the VirtualDOMElement class.<commit_after>'use strict';

const VirtualDOMNode = require('../virtualDOMNode');

class VirtualDOMElement extends VirtualDOMNode {
  constructor(tagName, props) {
    const domElement = document.createElement(tagName);

    super(props, domElement);
  }

  mount(parent, reference, context) {
    super.mount(parent, reference);

    const childParent = this,
          childReference = null,
          childContext = context;

    this.children.forEach(function(child) {
      child.mount(childParent, childReference, childContext);
    });

    this.applyProps();
  }

  unmount(context) {
    const childContext = context;

    this.children.forEach(function(child) {
      child.unmount(childContext);
    });

    super.unmount();
  }

  getTagName() {
    const domElement = this.getDOMElement(),
          tagName = domElement.tagName; 

    return tagName;
  }

  spliceChildren(start, removedChildrenCount, addedChildren, context) {
    const childParent = this,
          childReference = null,
          childContext = context;

    addedChildren.forEach(function(addedChild) {
      addedChild.mount(childParent, childReference, childContext);
    });

    const args = [start, removedChildrenCount].concat(addedChildren),
          removedChildren = Array.prototype.splice.apply(this.children, args);

    removedChildren.forEach(function(removedChild) {
      removedChild.unmount(childContext);
    });
  }

  addChild(child, context) {
    const start = Infinity,
          removedChildrenCount = 0,
          addedChildren = [child];

    this.spliceChildren(start, removedChildrenCount, addedChildren, context);
  }

  removeChild(child, context) {
    const index = this.children.indexOf(child);

    if (index > -1) {
      const start = index,
            removedChildrenCount = 1,
            addedChildren = [];

      this.spliceChildren(start, removedChildrenCount, addedChildren, context);
    }
  }
  
  setAttribute(name, value) {
    if (name === 'className') {
      name = 'class';
    }
    
    if (name === 'htmlFor') {
      name = 'for';
    }

    if (false) {

    } else if (typeof value === 'object') {
      const keys = Object.keys(value);

      keys.forEach(function (key) {
        this.domElement[name][key] = value[key];
      }.bind(this));
    } else if (typeof value === 'boolean') {
      if (value) {
        value = name; ///

        this.domElement.setAttribute(name, value);
      }
    } else {
      this.domElement.setAttribute(name, value);
    }
  }

  getAttribute(name) { return this.domElement.getAttribute(name); }

  clearAttribute(name) { this.domElement.removeAttribute(name); }

  setClass(className) { this.domElement.className = className; }

  addClass(className) { this.domElement.classList.add(className); }

  removeClass(className) { this.domElement.classList.remove(className); }

  toggleClass(className) { this.domElement.classList.toggle(className); }

  hasClass(className) { return this.domElement.classList.contains(className); }

  clearClasses() { this.domElement.className = ''; }

  applyProps() {
{'fraction_non_alphanumeric': 0.12438286351329829, 'fraction_numerical': 0.0009555661729574773, 'mean_word_length': 3.017914267434421, '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': '7133939', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1795, 'n_words': 333}