Browse files

Add Bundle dependencies as paused dependencies, so that they aren't e…

…valuated until they're used.
  • Loading branch information...
1 parent 302dc06 commit 78a4d28d0fec538128463dc94044e73b04f5f142 Kenneth Kufluk committed Mar 19, 2012
Showing with 32 additions and 24 deletions.
  1. +17 −24 src/loadrunner.js
  2. +1 −0 test/modules/modcompiled.js
  3. +14 −0 test/test.html
View
41 src/loadrunner.js
@@ -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);
};
View
1 test/modules/modcompiled.js
@@ -1,4 +1,5 @@
provide('thing', function(exports) {
+ window.thingLoaded = true;
exports('thing');
});
View
14 test/test.html
@@ -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() {

0 comments on commit 78a4d28

Please sign in to comment.