<commit_before>part of nest_ui;

abstract class ComponentHeritage {

  /** Very important! This is why the library is called nest_ui. Components are nested.
   *  This method goes through the #dom_element descendants looking for elements which
   *  have data-component-class attribute. If found, a new Component is created with the class
   *  specified in this attribute. Obviously, you should define such a class beforehand and
   *  inherit from Component.
  */
  void initChildComponents({ recursive: true }) {

    var elements = _findChildComponentDomElements(this.dom_element);
    elements.forEach((el) {
      [Component.app_library, 'nest_ui'].forEach((l) {
        var component = new_instance_of(el.getAttribute('data-component-class'), [], l);
        if(component != null) {
          component.dom_element = el;
          this.addChild(component);
          component.afterInitialize();
          if(recursive)
            component.initChildComponents();
        }
      });
    });
  }

  /** Finds immediate children with a specific role */
  List<Component> findChildrenByRole(r) {
    var children_with_roles = [];<commit_msg>Fix: change initChildComponents intiailization order - first init children, then run afterInitialize()<commit_after>part of nest_ui;

abstract class ComponentHeritage {

  /** Very important! This is why the library is called nest_ui. Components are nested.
   *  This method goes through the #dom_element descendants looking for elements which
   *  have data-component-class attribute. If found, a new Component is created with the class
   *  specified in this attribute. Obviously, you should define such a class beforehand and
   *  inherit from Component.
  */
  void initChildComponents({ recursive: true }) {

    var elements = _findChildComponentDomElements(this.dom_element);
    elements.forEach((el) {
      [Component.app_library, 'nest_ui'].forEach((l) {
        var component = new_instance_of(el.getAttribute('data-component-class'), [], l);
        if(component != null) {
          // The order is very important here: we want to first assign dom_element, add
          // component as a child to its parent and init its own children. Only then we
          // call afterInitialize() giving users access to everything we possible can.
          component.dom_element = el;
          this.addChild(component);
          if(recursive)
            component.initChildComponents();
          component.afterInitialize();
        }
      });
    });
  }

  /** Finds immediate children with a specific role */
  List<Component> findChildrenByRole(r) {
    var children_with_roles = [];
{'fraction_non_alphanumeric': 0.09032501889644746, 'fraction_numerical': 0.0, 'mean_word_length': 3.1230529595015577, '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': '3850346', 'n_tokens_mistral': 684, 'n_tokens_neox': 672, 'n_words': 232}