<commit_before>// Hot Module Replacement
export function bootloader(main: any) {
  switch (document.readyState) {
    case 'loading':
      document.addEventListener('DOMContentLoaded', () => main());
      break;
    case 'interactive':
    case 'complete':
    default:
      main();
  }
}


// create new elements
export function createNewHosts(cmps: any) {
    const components = cmps.map((componentNode: any) => {
      const newNode = document.createElement(componentNode.tagName);
      // display none
      const currentDisplay = newNode.style.display;
      newNode.style.display = 'none';
      const parentNode = componentNode.parentNode;
      parentNode.insertBefore(newNode, componentNode);
      return { currentDisplay, newNode };
    });
    return () => {
        components.forEach((cmp:any) => {
            cmp.newNode.style.display = cmp.currentDisplay;
            cmp.newNode = null;
            cmp.currentDisplay = null;
        });
    }
}


// remove old styles
export function removeNgStyles() {
    var docHead = document.head;
    Array.prototype.slice.call(docHead.querySelectorAll('style'), 0)
      .filter((style:any) => style.innerText.indexOf('_ng') !== -1)
      .map((el:any) => docHead.removeChild(el));
}
<commit_msg>fix(render): fix duplicated elements with angular 4.2.x+ (#53)<commit_after>// Hot Module Replacement
export function bootloader(main: any) {
  switch (document.readyState) {
    case 'loading':
      document.addEventListener('DOMContentLoaded', () => main());
      break;
    case 'interactive':
    case 'complete':
    default:
      main();
  }
}


// create new elements
export function createNewHosts(cmps: any) {
    const components = cmps.map((componentNode: any) => {
      const newNode = document.createElement(componentNode.tagName);
      const parentNode = componentNode.parentNode;
      parentNode.insertBefore(newNode, componentNode);
      return componentNode;
    });
    return () => {
        components.forEach((componentNode:any) => {
            componentNode.remove();
        });
    }
}


// remove old styles
export function removeNgStyles() {
    var docHead = document.head;
    Array.prototype.slice.call(docHead.querySelectorAll('style'), 0)
      .filter((style:any) => style.innerText.indexOf('_ng') !== -1)
      .map((el:any) => docHead.removeChild(el));
}

{'fraction_non_alphanumeric': 0.13837011884550085, 'fraction_numerical': 0.003395585738539898, 'mean_word_length': 3.092013888888889, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1595040', 'n_tokens_mistral': 682, 'n_tokens_neox': 673, 'n_words': 142}