Skip to content

Commit

Permalink
now looks for inprogress bundle in the case of a file existing in mul…
Browse files Browse the repository at this point in the history
…tiple bundles
  • Loading branch information
danwrong committed Aug 7, 2014
1 parent f303f9f commit 2413763
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
7 changes: 2 additions & 5 deletions Makefile
Expand Up @@ -7,22 +7,19 @@ dist/%.js: src/%.js
`npm bin`/uglifyjs -o $@ $<

dist:
mkdir -p dist

dist/plugins: dist
mkdir -p dist/plugins

main: dist js plugins

plugins: dist/plugins/amd.js dist/plugins/defer.js dist/plugins/json.js dist/plugins/requirejs.js
plugins: dist/plugins/amd.js dist/plugins/defer.js dist/plugins/json.js

js: dist/loadrunner.js

clean:
rm -rf dist

testserver: .
./test/bin/server
./test/server

test: .
open 'http://localhost:8080/test/index.html'
26 changes: 22 additions & 4 deletions src/loadrunner.js
Expand Up @@ -156,6 +156,7 @@

Script.prototype.start = function() {
var me = this, bundle;
// Here be the bit wot I have to change
if (bundle = findBundle(this.id)) {
bundle.then(function() {
me.start();
Expand Down Expand Up @@ -474,20 +475,37 @@
}
Sequence.prototype.forceFetch = forceFetch;

var definedBundles = [];
function Manifest() {
this.entries = {};
}
Manifest.prototype.push = function(bundle) {
var b;

This comment has been minimized.

Copy link
@alexgorbatchev

alexgorbatchev Aug 11, 2014

Single letter variables aren't cool 👎


for (var file in bundle) {
definedBundles[file] = new Bundle(file, bundle[file]);
b = new Bundle(file, bundle[file]);

for (var i=0, alias; alias = bundle[file][i]; i++) {
this.entries[alias] = definedBundles[file];
this.entries[alias] = this.entries[alias] || [];
this.entries[alias].push(b);
}
}

}
Manifest.prototype.get = function(key) {
return this.entries[key];
if (typeof this.entries[key] == 'undefined') {
console.log(key, 'not in bundle');
return null;
}

for (var i=0, candidate; candidate = this.entries[key][i]; i++) {
if (typeof candidate.startTime != 'undefined') {
console.log(key, 'found in other inprogress bundle', candidate.id);
return candidate;
}
}

console.log(key, 'found in bundle', this.entries[key][0].id);
return this.entries[key][0];
}


Expand Down
1 change: 1 addition & 0 deletions test/test.html
Expand Up @@ -313,6 +313,7 @@ <h2 id="qunit-userAgent"></h2>
equals(false, window.thingLoaded);
using.bundles.push({ 'modules/modcompiled.js': ['thing', 'another'] });
using('another', function(a) {
console.log('hello');
equals(a, 'another');
equals(false, window.thingLoaded);
start();
Expand Down

0 comments on commit 2413763

Please sign in to comment.