<commit_before>
exports.Component = require('./component');

exports.init = function (func, options, root) {
  var argsLength = arguments.length;
  if (argsLength === 1 && !exports.isFunction(arguments[0])) {
    options = arguments[0];
    func = null;
  }
  root = root || document;
  options = options || {};
  exports.defaults(options, {
    publishProgress: false,
    ignoreNotFound: false,
    componentSelector: '[data-component]',
    componentAttribute: 'data-component',
    optionsAttribute: 'data-attrs',
    optionsAttrPrefix: 'data-attr-',
    readyTopic: 'ui.ready',
    initializingTopic: 'ui.initializing'
  });
  var pub = function (topic, data) {
    var e = exports.createEvent('pubsub.' + topic,
      { topic: topic, data: data }
    );
    document.dispatchEvent(e);
  };
  exports.documentReady(function () {
    if (func) { func(); }
    var nodes = [].slice.call(root.querySelectorAll(options.componentSelector));
    var componentCount = nodes.length;
    function deferedForEach (fn) {
      var arr = this, i = 0, l = this.length;
      function next () {
        if (i >= l) { return; }
        fn(arr[i], i++);
        exports.defer(next);
      }
      next();
    }
    var f = options.publishProgress ? deferedForEach : Array.prototype.forEach;
    f.call(nodes, function (node, index) {
      if (options.publishProgress) {
        pub(options.initializingTopic, {
          componentCount: componentCount,
          progress: 100 * ((index + 1) / componentCount)
        });
      }
      var el, componentOptions = {}, attrs, type, component, optAttrPrefixLength;
      type = node.getAttribute(options.componentAttribute);
      componentOptions.id = node.id;
      if (node.hasAttribute(options.optionsAttribute)) {
        componentOptions = JSON.parse(node.getAttribute(options.optionsAttribute));
      } else {
        attrs = [].slice.call(node.attributes);
        optAttrPrefixLength = options.optionsAttrPrefix.length;
        attrs.forEach(function (attr) {
          if (attr.name.substr(0, optAttrPrefixLength) === options.optionsAttrPrefix) {
            componentOptions[attr.name.substr(optAttrPrefixLength)] = attr.value;
          }
        });
      }
      el = (node.tagName.toLowerCase() === 'script') ? root : node;
      component = exports.registry.findComponent(type);
      if (component) {
        component.attachTo(el, componentOptions);
      } else if (!options.ignoreNotFound) {
        throw new Error('component ' + type + ' not found');
      }
    });
    pub(options.readyTopic, {});
  });
};

exports.mixins = {
  Hooked: require('./mixins/hooked'),
  Traceable: require('./mixins/traceable'),
  Listener: require('./mixins/listener'),
  PubSub: require('./mixins/pubsub'),
  View: require('./mixins/view'),
  Bound: require('./mixins/bound'),
  Validator: require('./mixins/validator')
};

exports.components = {};

exports.ext = {};

exports.registry = require('./registry');

var assign = require('lodash-node/modern/objects/assign');
assign(exports, require('./utils'));<commit_msg>changes init signature and fixes callback issue<commit_after>
exports.Component = require('./component');

exports.init = function (options, cb) {
  var argsLength = arguments.length;
  if (argsLength === 1 && !exports.isFunction(arguments[0])) {
    options = arguments[0];
    func = null;
  }
  options = options || {};
  exports.defaults(options, {
    root: document,
    publishProgress: false,
    ignoreNotFound: false,
    componentSelector: '[data-component]',
    componentAttribute: 'data-component',
    optionsAttribute: 'data-attrs',
    optionsAttrPrefix: 'data-attr-',
    readyTopic: 'ui.ready',
    initializingTopic: 'ui.initializing'
  });
  var pub = function (topic, data) {
    var e = exports.createEvent('pubsub.' + topic,
      { topic: topic, data: data }
    );
    document.dispatchEvent(e);
  };
  exports.documentReady(function () {
    var nodes = [].slice.call(options.root.querySelectorAll(options.componentSelector));
    var componentCount = nodes.length;
    function deferedForEach (fn) {
      var arr = this, i = 0, l = this.length;
      function next () {
        if (i >= l) { return; }
        fn(arr[i], i++);
        exports.defer(next);
      }
      next();
    }
    var f = options.publishProgress ? deferedForEach : Array.prototype.forEach;
    f.call(nodes, function (node, index) {
      if (options.publishProgress) {
        pub(options.initializingTopic, {
          componentCount: componentCount,
          progress: 100 * ((index + 1) / componentCount)
        });
      }
      var el, componentOptions = {}, attrs, type, component, optAttrPrefixLength;
      type = node.getAttribute(options.componentAttribute);
      componentOptions.id = node.id;
      if (node.hasAttribute(options.optionsAttribute)) {
        componentOptions = JSON.parse(node.getAttribute(options.optionsAttribute));
      } else {
        attrs = [].slice.call(node.attributes);
        optAttrPrefixLength = options.optionsAttrPrefix.length;
        attrs.forEach(function (attr) {
          if (attr.name.substr(0, optAttrPrefixLength) === options.optionsAttrPrefix) {
            componentOptions[attr.name.substr(optAttrPrefixLength)] = attr.value;
          }
        });
      }
      el = (node.tagName.toLowerCase() === 'script') ? options.root : node;
      component = exports.registry.findComponent(type);
      if (component) {
        component.attachTo(el, componentOptions);
      } else if (!options.ignoreNotFound) {
        throw new Error('component ' + type + ' not found');
      }
    });
    if (cb) { cb(); }
    pub(options.readyTopic, {});
  });
};

exports.mixins = {
  Hooked: require('./mixins/hooked'),
  Traceable: require('./mixins/traceable'),
  Listener: require('./mixins/listener'),
  PubSub: require('./mixins/pubsub'),
  View: require('./mixins/view'),
  Bound: require('./mixins/bound'),
  Validator: require('./mixins/validator')
};

exports.components = {};

exports.ext = {};

exports.registry = require('./registry');

var assign = require('lodash-node/modern/objects/assign');
assign(exports, require('./utils'));

{'fraction_non_alphanumeric': 0.15215979214030528, 'fraction_numerical': 0.002923026956804157, 'mean_word_length': 3.0788079470198677, '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': '4171947', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1769, 'n_words': 357}