Skip to content

Commit

Permalink
Add Bundle dependencies as paused dependencies, so that they aren't e…
Browse files Browse the repository at this point in the history
…valuated until they're used.
  • Loading branch information
kennethkufluk committed Mar 19, 2012
1 parent 302dc06 commit 78a4d28
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
41 changes: 17 additions & 24 deletions src/loadrunner.js
Expand Up @@ -288,39 +288,32 @@
function Bundle(id, contents) {
this.id = id;
this.contents = contents;
if (id.match(/\.js$/)) {
this.path = path(using.path, id);
} else {
this.path = Module.prototype.resolvePath(id);
}
this.dep = createDependency(id);
this.deps = [];
this.path = this.dep.path;
}
Bundle.prototype = new Script;
Bundle.prototype.start = function() {
var me = this, def, file;
var me = this, def, dep, key;
for (var i=0, l=this.contents.length; i<l; i++) {
file = this.contents[i];
if (file.match(/\.js$/)) {
file = 'script_' + file;
} else {
file = 'module_' + file;
}
if (!metDependencies[file] && !inProgressDependencies[file]) {
inProgressDependencies[file] = this;
dep = createDependency(this.contents[i]);
this.deps.push(dep);
key = dep.key();

if (!metDependencies[key] && !inProgressDependencies[key] && !pausedDependencies[key]) {
pausedDependencies[key] = this;
}
}
Script.prototype.start.call(this);
};
Bundle.prototype.loaded = function() {
var p, exports, me = this, file;
for (var i=0, l=this.contents.length; i<l; i++) {
file = this.contents[i];
if (file.match(/\.js$/)) {
file = 'script_' + file;
} else {
file = 'module_' + file;
}
delete inProgressDependencies[file];
metDependencies[file] = this;
var p, exports, me = this, dep;
for (var i=0, l=this.deps.length; i<l; i++) {
dep = this.deps[i];
key = dep.key();

delete pausedDependencies[key];
metDependencies[key] = this;
}
Script.prototype.loaded.call(this);
};
Expand Down
1 change: 1 addition & 0 deletions test/modules/modcompiled.js
@@ -1,4 +1,5 @@
provide('thing', function(exports) {
window.thingLoaded = true;
exports('thing');
});

Expand Down
14 changes: 14 additions & 0 deletions test/test.html
Expand Up @@ -305,6 +305,20 @@ <h2 id="qunit-userAgent"></h2>
});
});

QUnit.test('should only evaluate required modules from a bundle', function() {
expect(3);
stop(2000);
loadrunner.reset();
window.thingLoaded = false;
equals(false, window.thingLoaded);
using.bundles.push({ 'modules/modcompiled.js': ['thing', 'another'] });
using('another', function(a) {
equals(a, 'another');
equals(false, window.thingLoaded);
start();
});
});


QUnit.module('Autofetch tests', {
teardown: function() {
Expand Down

0 comments on commit 78a4d28

Please sign in to comment.