<commit_before>/* global moduleAccess:true */
/* jshint unused:false */
var moduleAccess = function (partAccess, eventBus) {
   'use strict';

   var loadedModules = {},
      availableModuleDescriptors = {};


   function addModuleDescriptor(moduleDescriptor) {
      availableModuleDescriptors[moduleDescriptor.name] = moduleDescriptor;
   }


   function initializeModules(element) {
      var moduleNames = element.getAttribute('modules'),
         moduleNamesArray = moduleNames.split(',');

      each(moduleNamesArray, function (i, moduleName) {
         moduleName = moduleName.trim();
         initializeModule(element, moduleName);
      });
   }

   function initializeModule(element, moduleName) {
      var moduleDescriptor,
         foundDependencies;

      //check if module to be loaded is registered
      if (availableModuleDescriptors.hasOwnProperty(moduleName)) {
         moduleDescriptor = availableModuleDescriptors[moduleName];

         foundDependencies = partAccess.getParts(moduleDescriptor.dependencies);
         // check if all needed dependencies are found
         if (foundDependencies.length === moduleDescriptor.dependencies.length) {
            buildModule(element, moduleDescriptor, foundDependencies);
         } else {
            throw new Error('Required Parts Missing from ' + moduleName + ' dependencies: ' + JSON.stringify(moduleDescriptor.dependencies));
         }
      } else {
         throw new Error('Module ' + moduleName + ' not registered but found in dom');
      }
   }

   function buildModule(element, moduleDescriptor, foundDependencies) {
      //build arguments
      var args = foundDependencies,
         domSettings = getDOMSettings(element, moduleDescriptor.name),
         mergedSettings,
         createdModule,
         name;

      if (moduleDescriptor.settings !== undefined || domSettings !== undefined) {
         //override module settings with found dom settings into new object
         mergedSettings = merge({}, moduleDescriptor.settings, domSettings);

         args.unshift(mergedSettings);
      }

      //make moduleDomElement first arguments
      args.unshift(element);

      //create Module
      createdModule = moduleDescriptor.creator.apply(null, args);

      if (createdModule === undefined) {
         createdModule = {};
      }

      loadedModules[name] = createdModule;

      //add module to eventBus
      eventBus.add(createdModule);
   }


   function getDOMSettings(element, moduleName) {

      var settingsScript = element.querySelector('script[type="' + moduleName + '/settings"]'),
         settingsAsHtml,
         settings;

      if (settingsScript !== null) {
         settingsAsHtml = settingsScript.innerHTML;
         settings = JSON.parse(settingsAsHtml);
      }

      return settings;
   }


   function callPostConstructs() {
      callPostConstruct(loadedModules);

      function callPostConstruct(store) {
         var elementName,
            element;

         for (elementName in store) {
            if (store.hasOwnProperty(elementName)) {
               element = store[elementName];
               if (typeof element.postConstruct === 'function') {
                  element.postConstruct();
               }
            }

         }
      }
   }

   function merge(mergeInto, overrider) {
      var i,
         key;

      for (i = 1; i < arguments.length; i++) {
         for (key in arguments[i]) {
            if (arguments[i].hasOwnProperty(key)) {
               arguments[0][key] = arguments[i][key];
            }
         }
      }

      return arguments[0];
   }

   function reset() {
      loadedModules = {};
      availableModuleDescriptors = {};
   }


   return {
      reset: reset,
      provisionModule: initializeModules,
      provisionFinished: callPostConstructs,
      addModuleDescriptor: addModuleDescriptor<commit_msg>removed unused parameters<commit_after>/* global moduleAccess:true */
/* jshint unused:false */
var moduleAccess = function (partAccess, eventBus) {
   'use strict';

   var loadedModules = {},
      availableModuleDescriptors = {};


   function addModuleDescriptor(moduleDescriptor) {
      availableModuleDescriptors[moduleDescriptor.name] = moduleDescriptor;
   }


   function initializeModules(element) {
      var moduleNames = element.getAttribute('modules'),
         moduleNamesArray = moduleNames.split(',');

      each(moduleNamesArray, function (i, moduleName) {
         moduleName = moduleName.trim();
         initializeModule(element, moduleName);
      });
   }

   function initializeModule(element, moduleName) {
      var moduleDescriptor,
         foundDependencies;

      //check if module to be loaded is registered
      if (availableModuleDescriptors.hasOwnProperty(moduleName)) {
         moduleDescriptor = availableModuleDescriptors[moduleName];

         foundDependencies = partAccess.getParts(moduleDescriptor.dependencies);
         // check if all needed dependencies are found
         if (foundDependencies.length === moduleDescriptor.dependencies.length) {
            buildModule(element, moduleDescriptor, foundDependencies);
         } else {
            throw new Error('Required Parts Missing from ' + moduleName + ' dependencies: ' + JSON.stringify(moduleDescriptor.dependencies));
         }
      } else {
         throw new Error('Module ' + moduleName + ' not registered but found in dom');
      }
   }

   function buildModule(element, moduleDescriptor, foundDependencies) {
      //build arguments
      var args = foundDependencies,
         domSettings = getDOMSettings(element, moduleDescriptor.name),
         mergedSettings,
         createdModule,
         name;

      if (moduleDescriptor.settings !== undefined || domSettings !== undefined) {
         //override module settings with found dom settings into new object
         mergedSettings = merge({}, moduleDescriptor.settings, domSettings);

         args.unshift(mergedSettings);
      }

      //make moduleDomElement first arguments
      args.unshift(element);

      //create Module
      createdModule = moduleDescriptor.creator.apply(null, args);

      if (createdModule === undefined) {
         createdModule = {};
      }

      loadedModules[name] = createdModule;

      //add module to eventBus
      eventBus.add(createdModule);
   }


   function getDOMSettings(element, moduleName) {

      var settingsScript = element.querySelector('script[type="' + moduleName + '/settings"]'),
         settingsAsHtml,
         settings;

      if (settingsScript !== null) {
         settingsAsHtml = settingsScript.innerHTML;
         settings = JSON.parse(settingsAsHtml);
      }

      return settings;
   }


   function callPostConstructs() {
      callPostConstruct(loadedModules);

      function callPostConstruct(store) {
         var elementName,
            element;

         for (elementName in store) {
            if (store.hasOwnProperty(elementName)) {
               element = store[elementName];
               if (typeof element.postConstruct === 'function') {
                  element.postConstruct();
               }
            }

         }
      }
   }

   function merge() {
      var i,
         key;

      for (i = 1; i < arguments.length; i++) {
         for (key in arguments[i]) {
            if (arguments[i].hasOwnProperty(key)) {
               arguments[0][key] = arguments[i][key];
            }
         }
      }

      return arguments[0];
   }

   function reset() {
      loadedModules = {};
      availableModuleDescriptors = {};
   }


   return {
      reset: reset,
      provisionModule: initializeModules,
      provisionFinished: callPostConstructs,
      addModuleDescriptor: addModuleDescriptor
{'fraction_non_alphanumeric': 0.09721146398140976, 'fraction_numerical': 0.000774593338497289, 'mean_word_length': 2.461572832886506, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4418761', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1859, 'n_words': 438}