<commit_before>package doom;

import js.html.Element;
using doom.Patch;

class Component<State> implements IComponent {
  public static function mount(component : IComponent, ref : Element) {
    if(null == ref)
      throw 'reference element is set to null';
    ref.innerHTML = "";
    component.init();
    ref.appendChild(component.element);
  }

  public var element : Element;
  public var node : Node;
  public var state : State;

  public function new(state : State) {
    this.state = state;
    this.node = render();
  }

  public function init() {
    // TODO should this be js.html.Node
    element = cast HtmlNode.toHtml(node);
  }

  private function updateNode(oldNode : Node) {
    var newNode = render(),
        patches = oldNode.diff(newNode);
    HtmlNode.applyPatches(patches, element);
    node = newNode;
  }
<commit_msg>throw error if component return non-element node<commit_after>package doom;

import js.html.Element;
using doom.Patch;

class Component<State> implements IComponent {
  public static function mount(component : IComponent, ref : Element) {
    if(null == ref)
      throw 'reference element is set to null';
    ref.innerHTML = "";
    component.init();
    ref.appendChild(component.element);
  }

  public var element : Element;
  public var node : Node;
  public var state : State;

  public function new(state : State) {
    this.state = state;
    this.node = render();
  }

  public function init() {
    // TODO should this be js.html.Node
    element = cast HtmlNode.toHtml(node);
  }

  private function updateNode(oldNode : Node) {
    var newNode = render();
    switch newNode {
      case doom.Node.NodeImpl.Element(_): // do nothing
      case _: throw new thx.Error('Component can (and must) return only element nodes');
    }
    var patches = oldNode.diff(newNode);
    HtmlNode.applyPatches(patches, element);
    node = newNode;
  }

{'fraction_non_alphanumeric': 0.10870712401055409, 'fraction_numerical': 0.0, 'mean_word_length': 3.1762114537444934, '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': '731338', 'n_tokens_mistral': 567, 'n_tokens_neox': 552, 'n_words': 170}