Skip to content

Commit

Permalink
Merge pull request #28 from kratiahuja/master
Browse files Browse the repository at this point in the history
Avoid double walking of all modules
  • Loading branch information
chadhietala committed Jun 20, 2016
2 parents d2cf267 + 03ded75 commit 1b0d7e4
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,26 @@ import Ember from 'ember';
export default function(app, prefix) {
var regex = new RegExp('^' + prefix + '\/((?:instance-)?initializers)\/');
var getKeys = (Object.keys || Ember.keys);
var moduleNames = getKeys(requirejs._eak_seen);

getKeys(requirejs._eak_seen).map(function (moduleName) {
return {
moduleName: moduleName,
matches: regex.exec(moduleName)
};
})
.filter(function(dep) {
return dep.matches && dep.matches.length === 2;
})
.forEach(function(dep) {
var moduleName = dep.moduleName;
for (var i = 0; i < moduleNames.length; i++) {
var moduleName = moduleNames[i];
var matches = regex.exec(moduleName);

var module = require(moduleName, null, null, true);
if (!module) { throw new Error(moduleName + ' must export an initializer.'); }
if (matches && matches.length === 2) {
var module = require(moduleName, null, null, true);
if (!module) { throw new Error(moduleName + ' must export an initializer.'); }

var initializerType = Ember.String.camelize(dep.matches[1].substring(0, dep.matches[1].length - 1));
var initializer = module['default'];
if (!initializer.name) {
var initializerName = moduleName.match(/[^\/]+\/?$/)[0];
initializer.name = initializerName;
}
var initializerType = Ember.String.camelize(matches[1].substring(0, matches[1].length - 1));
var initializer = module['default'];
if (!initializer.name) {
var initializerName = moduleName.match(/[^\/]+\/?$/)[0];
initializer.name = initializerName;
}

if (app[initializerType]) {
app[initializerType](initializer);
if (app[initializerType]) {
app[initializerType](initializer);
}
}
});
}
}

0 comments on commit 1b0d7e4

Please sign in to comment.