Comparing version 3.2.0 to 3.2.1
{ | ||
"name": "loadjs", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "authors": [ |
# LoadJS Changelog | ||
## 3.2.1 - December 18, 2016 | ||
* Minor code cleanup | ||
## 3.2.0 - December 11, 2016 | ||
@@ -4,0 +8,0 @@ |
@@ -21,7 +21,10 @@ loadjs = (function () { | ||
bundleIds = bundleIds.push ? bundleIds : [bundleIds]; | ||
var depsNotFound = [], | ||
i = bundleIds.length, | ||
numWaiting = i, | ||
fn, bundleId, r, q; | ||
fn, | ||
bundleId, | ||
r, | ||
q; | ||
@@ -39,3 +42,3 @@ // define callback function | ||
bundleId = bundleIds[i]; | ||
// execute callback if in result cache | ||
@@ -47,3 +50,3 @@ r = bundleResultCache[bundleId]; | ||
} | ||
// add to callback queue | ||
@@ -66,6 +69,6 @@ q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || []; | ||
var q = bundleCallbackQueue[bundleId]; | ||
// cache result | ||
bundleResultCache[bundleId] = pathsNotFound; | ||
// exit if queue is empty | ||
@@ -91,3 +94,3 @@ if (!q) return; | ||
maxTries = (args.numRetries || 0) + 1, | ||
beforeCallbackFn = (args.before || devnull), | ||
beforeCallbackFn = args.before || devnull, | ||
isCss, | ||
@@ -109,3 +112,3 @@ e; | ||
e.src = path; | ||
e.async = (async === undefined) ? true : async; | ||
e.async = async === undefined ? true : async; | ||
} | ||
@@ -145,3 +148,3 @@ | ||
beforeCallbackFn(path, e); | ||
// add to document | ||
@@ -161,3 +164,7 @@ doc.head.appendChild(e); | ||
var numWaiting = paths.length, x = numWaiting, pathsNotFound = [], fn, i; | ||
var numWaiting = paths.length, | ||
x = numWaiting, | ||
pathsNotFound = [], | ||
fn, | ||
i; | ||
@@ -175,7 +182,7 @@ // define callback function | ||
} | ||
numWaiting--; | ||
if (!numWaiting) callbackFn(pathsNotFound); | ||
}; | ||
// load scripts | ||
@@ -194,3 +201,4 @@ for (i=0; i < x; i++) loadFile(paths[i], fn, args); | ||
function loadjs(paths, arg1, arg2) { | ||
var bundleId, args; | ||
var bundleId, | ||
args; | ||
@@ -202,3 +210,3 @@ // bundleId (if string) | ||
args = (bundleId ? arg2 : arg1) || {}; | ||
// throw error if bundle is already defined | ||
@@ -212,3 +220,3 @@ if (bundleId) { | ||
} | ||
// load scripts | ||
@@ -238,3 +246,3 @@ loadFiles(paths, function(pathsNotFound) { | ||
}); | ||
return loadjs; | ||
@@ -241,0 +249,0 @@ }; |
@@ -29,7 +29,10 @@ (function(root, factory) { | ||
bundleIds = bundleIds.push ? bundleIds : [bundleIds]; | ||
var depsNotFound = [], | ||
i = bundleIds.length, | ||
numWaiting = i, | ||
fn, bundleId, r, q; | ||
fn, | ||
bundleId, | ||
r, | ||
q; | ||
@@ -47,3 +50,3 @@ // define callback function | ||
bundleId = bundleIds[i]; | ||
// execute callback if in result cache | ||
@@ -55,3 +58,3 @@ r = bundleResultCache[bundleId]; | ||
} | ||
// add to callback queue | ||
@@ -74,6 +77,6 @@ q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || []; | ||
var q = bundleCallbackQueue[bundleId]; | ||
// cache result | ||
bundleResultCache[bundleId] = pathsNotFound; | ||
// exit if queue is empty | ||
@@ -99,3 +102,3 @@ if (!q) return; | ||
maxTries = (args.numRetries || 0) + 1, | ||
beforeCallbackFn = (args.before || devnull), | ||
beforeCallbackFn = args.before || devnull, | ||
isCss, | ||
@@ -117,3 +120,3 @@ e; | ||
e.src = path; | ||
e.async = (async === undefined) ? true : async; | ||
e.async = async === undefined ? true : async; | ||
} | ||
@@ -153,3 +156,3 @@ | ||
beforeCallbackFn(path, e); | ||
// add to document | ||
@@ -169,3 +172,7 @@ doc.head.appendChild(e); | ||
var numWaiting = paths.length, x = numWaiting, pathsNotFound = [], fn, i; | ||
var numWaiting = paths.length, | ||
x = numWaiting, | ||
pathsNotFound = [], | ||
fn, | ||
i; | ||
@@ -183,7 +190,7 @@ // define callback function | ||
} | ||
numWaiting--; | ||
if (!numWaiting) callbackFn(pathsNotFound); | ||
}; | ||
// load scripts | ||
@@ -202,3 +209,4 @@ for (i=0; i < x; i++) loadFile(paths[i], fn, args); | ||
function loadjs(paths, arg1, arg2) { | ||
var bundleId, args; | ||
var bundleId, | ||
args; | ||
@@ -210,3 +218,3 @@ // bundleId (if string) | ||
args = (bundleId ? arg2 : arg1) || {}; | ||
// throw error if bundle is already defined | ||
@@ -220,3 +228,3 @@ if (bundleId) { | ||
} | ||
// load scripts | ||
@@ -246,3 +254,3 @@ loadFiles(paths, function(pathsNotFound) { | ||
}); | ||
return loadjs; | ||
@@ -249,0 +257,0 @@ }; |
window.timesLoaded1 = window.timesLoaded1 || 0; | ||
log('file1: loaded (' + timesLoaded1 + ')'); | ||
timesLoaded1 +=1; | ||
timesLoaded1 += 1; |
window.timesLoaded2 = window.timesLoaded2 || 0; | ||
log('file2: loaded (' + timesLoaded2 + ')'); | ||
timesLoaded2 +=1; | ||
timesLoaded2 += 1; |
@@ -21,7 +21,10 @@ loadjs = (function () { | ||
bundleIds = bundleIds.push ? bundleIds : [bundleIds]; | ||
var depsNotFound = [], | ||
i = bundleIds.length, | ||
numWaiting = i, | ||
fn, bundleId, r, q; | ||
fn, | ||
bundleId, | ||
r, | ||
q; | ||
@@ -39,3 +42,3 @@ // define callback function | ||
bundleId = bundleIds[i]; | ||
// execute callback if in result cache | ||
@@ -47,3 +50,3 @@ r = bundleResultCache[bundleId]; | ||
} | ||
// add to callback queue | ||
@@ -66,6 +69,6 @@ q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || []; | ||
var q = bundleCallbackQueue[bundleId]; | ||
// cache result | ||
bundleResultCache[bundleId] = pathsNotFound; | ||
// exit if queue is empty | ||
@@ -91,3 +94,3 @@ if (!q) return; | ||
maxTries = (args.numRetries || 0) + 1, | ||
beforeCallbackFn = (args.before || devnull), | ||
beforeCallbackFn = args.before || devnull, | ||
isCss, | ||
@@ -109,3 +112,3 @@ e; | ||
e.src = path; | ||
e.async = (async === undefined) ? true : async; | ||
e.async = async === undefined ? true : async; | ||
} | ||
@@ -145,3 +148,3 @@ | ||
beforeCallbackFn(path, e); | ||
// add to document | ||
@@ -161,3 +164,7 @@ doc.head.appendChild(e); | ||
var numWaiting = paths.length, x = numWaiting, pathsNotFound = [], fn, i; | ||
var numWaiting = paths.length, | ||
x = numWaiting, | ||
pathsNotFound = [], | ||
fn, | ||
i; | ||
@@ -175,7 +182,7 @@ // define callback function | ||
} | ||
numWaiting--; | ||
if (!numWaiting) callbackFn(pathsNotFound); | ||
}; | ||
// load scripts | ||
@@ -194,3 +201,4 @@ for (i=0; i < x; i++) loadFile(paths[i], fn, args); | ||
function loadjs(paths, arg1, arg2) { | ||
var bundleId, args; | ||
var bundleId, | ||
args; | ||
@@ -202,3 +210,3 @@ // bundleId (if string) | ||
args = (bundleId ? arg2 : arg1) || {}; | ||
// throw error if bundle is already defined | ||
@@ -212,3 +220,3 @@ if (bundleId) { | ||
} | ||
// load scripts | ||
@@ -238,3 +246,3 @@ loadFiles(paths, function(pathsNotFound) { | ||
}); | ||
return loadjs; | ||
@@ -241,0 +249,0 @@ }; |
@@ -12,3 +12,3 @@ 'use strict'; | ||
return 'loadjs'; | ||
} | ||
}; | ||
@@ -21,3 +21,3 @@ | ||
gulp.task('examples:build', gulp.series( | ||
gulp.task('build-examples', gulp.series( | ||
clean('./examples/assets/loadjs'), | ||
@@ -28,3 +28,3 @@ buildJs('./examples/assets/loadjs') | ||
gulp.task('dist:build', gulp.series( | ||
gulp.task('build-dist', gulp.series( | ||
clean('./dist'), | ||
@@ -38,3 +38,3 @@ gulp.parallel( | ||
gulp.task('test:build', gulp.series( | ||
gulp.task('build-tests', gulp.series( | ||
clean('./test/assets/loadjs'), | ||
@@ -46,5 +46,5 @@ buildJs('./test/assets/loadjs') | ||
gulp.task('build-all', gulp.parallel( | ||
'examples:build', | ||
'dist:build', | ||
'test:build' | ||
'build-examples', | ||
'build-dist', | ||
'build-tests' | ||
)); | ||
@@ -51,0 +51,0 @@ |
{ | ||
"name": "loadjs", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"license": "MIT", | ||
@@ -21,2 +21,10 @@ "description": "Tiny async loader for modern browsers", | ||
"main": "dist/loadjs.umd.js", | ||
"scripts": { | ||
"build-all": "gulp build-all", | ||
"build-dist": "gulp build-dist", | ||
"build-examples": "gulp build-examples", | ||
"build-tests": "gulp build-tests", | ||
"gulp": "gulp", | ||
"http-server": "http-server" | ||
}, | ||
"devDependencies": { | ||
@@ -23,0 +31,0 @@ "del": "2.2.2", |
@@ -133,3 +133,8 @@ # LoadJS | ||
loadjs(['/path/to/foo.js', '/path/to/bar.js'], { | ||
before: function(path, scriptEl) { /* called for each script node before embedded */ } | ||
success: function() {}, | ||
error: function(pathsNotFound) {}, | ||
before: function(path, scriptEl) { | ||
/* called for each script node before being embedded */ | ||
if (path === '/path/to/foo.js') scriptEl.crossOrigin = true; | ||
} | ||
}); | ||
@@ -248,3 +253,3 @@ ``` | ||
```bash | ||
$ ./node_modules/.bin/gulp examples:build | ||
$ npm run build-examples | ||
``` | ||
@@ -256,3 +261,3 @@ | ||
$ npm install http-server | ||
$ ./node_modules/.bin/http-server -p 3000 | ||
$ npm run http-server -- -p 3000 | ||
``` | ||
@@ -265,3 +270,3 @@ | ||
```bash | ||
$ ./node_modules/.bin/gulp dist:build | ||
$ npm run build-dist | ||
``` | ||
@@ -271,10 +276,17 @@ | ||
## Run tests | ||
1. Run tests | ||
To run the browser tests first build the `loadjs` library: | ||
To run the browser tests first build the `loadjs` library: | ||
```bash | ||
$ ./node_modules/.bin/gulp test:build | ||
``` | ||
```bash | ||
$ npm run build-tests | ||
``` | ||
Then visit http://localhost:3000/test | ||
Then visit http://localhost:3000/test | ||
1. Build all files | ||
```bash | ||
$ npm run build-all | ||
``` | ||
@@ -6,3 +6,3 @@ # Release Instructions | ||
```bash | ||
$ ./node_modules/.bin/gulp build-all | ||
$ npm run build-all | ||
``` | ||
@@ -9,0 +9,0 @@ |
@@ -20,7 +20,10 @@ /** | ||
bundleIds = bundleIds.push ? bundleIds : [bundleIds]; | ||
var depsNotFound = [], | ||
i = bundleIds.length, | ||
numWaiting = i, | ||
fn, bundleId, r, q; | ||
fn, | ||
bundleId, | ||
r, | ||
q; | ||
@@ -38,3 +41,3 @@ // define callback function | ||
bundleId = bundleIds[i]; | ||
// execute callback if in result cache | ||
@@ -46,3 +49,3 @@ r = bundleResultCache[bundleId]; | ||
} | ||
// add to callback queue | ||
@@ -65,6 +68,6 @@ q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || []; | ||
var q = bundleCallbackQueue[bundleId]; | ||
// cache result | ||
bundleResultCache[bundleId] = pathsNotFound; | ||
// exit if queue is empty | ||
@@ -90,3 +93,3 @@ if (!q) return; | ||
maxTries = (args.numRetries || 0) + 1, | ||
beforeCallbackFn = (args.before || devnull), | ||
beforeCallbackFn = args.before || devnull, | ||
isCss, | ||
@@ -108,3 +111,3 @@ e; | ||
e.src = path; | ||
e.async = (async === undefined) ? true : async; | ||
e.async = async === undefined ? true : async; | ||
} | ||
@@ -144,3 +147,3 @@ | ||
beforeCallbackFn(path, e); | ||
// add to document | ||
@@ -160,3 +163,7 @@ doc.head.appendChild(e); | ||
var numWaiting = paths.length, x = numWaiting, pathsNotFound = [], fn, i; | ||
var numWaiting = paths.length, | ||
x = numWaiting, | ||
pathsNotFound = [], | ||
fn, | ||
i; | ||
@@ -174,7 +181,7 @@ // define callback function | ||
} | ||
numWaiting--; | ||
if (!numWaiting) callbackFn(pathsNotFound); | ||
}; | ||
// load scripts | ||
@@ -193,3 +200,4 @@ for (i=0; i < x; i++) loadFile(paths[i], fn, args); | ||
function loadjs(paths, arg1, arg2) { | ||
var bundleId, args; | ||
var bundleId, | ||
args; | ||
@@ -201,3 +209,3 @@ // bundleId (if string) | ||
args = (bundleId ? arg2 : arg1) || {}; | ||
// throw error if bundle is already defined | ||
@@ -211,3 +219,3 @@ if (bundleId) { | ||
} | ||
// load scripts | ||
@@ -237,3 +245,3 @@ loadFiles(paths, function(pathsNotFound) { | ||
}); | ||
return loadjs; | ||
@@ -240,0 +248,0 @@ }; |
@@ -21,7 +21,10 @@ loadjs = (function () { | ||
bundleIds = bundleIds.push ? bundleIds : [bundleIds]; | ||
var depsNotFound = [], | ||
i = bundleIds.length, | ||
numWaiting = i, | ||
fn, bundleId, r, q; | ||
fn, | ||
bundleId, | ||
r, | ||
q; | ||
@@ -39,3 +42,3 @@ // define callback function | ||
bundleId = bundleIds[i]; | ||
// execute callback if in result cache | ||
@@ -47,3 +50,3 @@ r = bundleResultCache[bundleId]; | ||
} | ||
// add to callback queue | ||
@@ -66,6 +69,6 @@ q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || []; | ||
var q = bundleCallbackQueue[bundleId]; | ||
// cache result | ||
bundleResultCache[bundleId] = pathsNotFound; | ||
// exit if queue is empty | ||
@@ -91,3 +94,3 @@ if (!q) return; | ||
maxTries = (args.numRetries || 0) + 1, | ||
beforeCallbackFn = (args.before || devnull), | ||
beforeCallbackFn = args.before || devnull, | ||
isCss, | ||
@@ -109,3 +112,3 @@ e; | ||
e.src = path; | ||
e.async = (async === undefined) ? true : async; | ||
e.async = async === undefined ? true : async; | ||
} | ||
@@ -145,3 +148,3 @@ | ||
beforeCallbackFn(path, e); | ||
// add to document | ||
@@ -161,3 +164,7 @@ doc.head.appendChild(e); | ||
var numWaiting = paths.length, x = numWaiting, pathsNotFound = [], fn, i; | ||
var numWaiting = paths.length, | ||
x = numWaiting, | ||
pathsNotFound = [], | ||
fn, | ||
i; | ||
@@ -175,7 +182,7 @@ // define callback function | ||
} | ||
numWaiting--; | ||
if (!numWaiting) callbackFn(pathsNotFound); | ||
}; | ||
// load scripts | ||
@@ -194,3 +201,4 @@ for (i=0; i < x; i++) loadFile(paths[i], fn, args); | ||
function loadjs(paths, arg1, arg2) { | ||
var bundleId, args; | ||
var bundleId, | ||
args; | ||
@@ -202,3 +210,3 @@ // bundleId (if string) | ||
args = (bundleId ? arg2 : arg1) || {}; | ||
// throw error if bundle is already defined | ||
@@ -212,3 +220,3 @@ if (bundleId) { | ||
} | ||
// load scripts | ||
@@ -238,3 +246,3 @@ loadFiles(paths, function(pathsNotFound) { | ||
}); | ||
return loadjs; | ||
@@ -241,0 +249,0 @@ }; |
@@ -14,3 +14,2 @@ /** | ||
beforeEach(function() { | ||
@@ -21,4 +20,2 @@ // reset register | ||
// ========================================================================== | ||
@@ -38,4 +35,4 @@ // JavaScript file loading tests | ||
}); | ||
it('should call error callback on invalid path', function(done) { | ||
@@ -81,4 +78,4 @@ loadjs(['assets/file-doesntexist.js'], { | ||
}); | ||
it('should call success callback on two valid paths', function(done) { | ||
@@ -94,3 +91,3 @@ loadjs(['assets/file1.js', 'assets/file2.js'], { | ||
it('should call error callback on one invalid path', function(done) { | ||
@@ -149,3 +146,3 @@ loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { | ||
}); | ||
} | ||
}; | ||
@@ -174,9 +171,9 @@ // run tests | ||
// custom filter under Options | ||
// | ||
// | ||
xit('it should report ad blocked scripts as missing', function(done) { | ||
var blockedScript = 'https://www.googletagservices.com/tag/js/gpt.js'; | ||
loadjs([blockedScript, 'assets/file1.js'], { | ||
success: function() { | ||
throw "Executed success callback"; | ||
throw new Error('Executed success callback'); | ||
}, | ||
@@ -194,3 +191,2 @@ error: function(pathsNotFound) { | ||
// ========================================================================== | ||
@@ -223,3 +219,3 @@ // CSS file loading tests | ||
el.parentNode.removeChild(el); | ||
} | ||
} | ||
} | ||
@@ -237,4 +233,4 @@ }); | ||
}); | ||
it('should load multiple files', function(done) { | ||
@@ -248,8 +244,8 @@ loadjs(['assets/file1.css', 'assets/file2.css'], { | ||
}); | ||
it('should call error callback on one invalid path', function(done) { | ||
loadjs(['assets/file1.css', 'assets/file-doesntexist.css'], { | ||
success: function() { | ||
throw "Executed success callback"; | ||
throw new Error('Executed success callback'); | ||
}, | ||
@@ -283,2 +279,3 @@ error: function(pathsNotFound) { | ||
var styleObj = getComputedStyle(testEl); | ||
assert.equal(styleObj.getPropertyValue('padding-left'), '15px'); | ||
@@ -296,6 +293,7 @@ done(); | ||
success: function() { | ||
throw "Executed success callback"; | ||
throw new Error('Executed success callback'); | ||
}, | ||
error: function(pathsNotFound) { | ||
var styleObj = getComputedStyle(testEl); | ||
assert.equal(styleObj.getPropertyValue('padding-left'), '0px'); | ||
@@ -317,3 +315,2 @@ assert.equal(pathsNotFound.length, 1); | ||
// ========================================================================== | ||
@@ -328,3 +325,3 @@ // API tests | ||
loadjs(['assets/file1.js'], 'bundle3'); | ||
// define bundle again | ||
@@ -334,7 +331,7 @@ var fn = function() { | ||
}; | ||
expect(fn).to.throw(Error, "LoadJS"); | ||
}); | ||
it('should create a bundle id and a callback inline', function(done) { | ||
@@ -355,7 +352,7 @@ loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', { | ||
} | ||
// define bundles | ||
loadjs('assets/file1.js', 'bundle5'); | ||
loadjs('assets/file2.js', 'bundle6'); | ||
loadjs | ||
@@ -374,8 +371,8 @@ .ready('bundle5', { | ||
}); | ||
it('should handle multiple dependencies', function(done) { | ||
loadjs('assets/file1.js', 'bundle7'); | ||
loadjs('assets/file2.js', 'bundle8'); | ||
loadjs.ready(['bundle7', 'bundle8'], { | ||
@@ -389,8 +386,8 @@ success: function() { | ||
}); | ||
it('should error on missing depdendencies', function(done) { | ||
loadjs('assets/file1.js', 'bundle9'); | ||
loadjs('assets/file-doesntexist.js', 'bundle10'); | ||
loadjs.ready(['bundle9', 'bundle10'], { | ||
@@ -408,4 +405,4 @@ success: function() { | ||
}); | ||
it('should execute callbacks on .done()', function(done) { | ||
@@ -418,12 +415,12 @@ // add handler | ||
}); | ||
// execute done | ||
loadjs.done('plugin1'); | ||
}); | ||
it('should execute callbacks created after .done()', function(done) { | ||
// execute done | ||
loadjs.done('plugin2'); | ||
// add handler | ||
@@ -436,8 +433,8 @@ loadjs.ready('plugin2', { | ||
}); | ||
it('should define bundles', function(done) { | ||
// define bundle | ||
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); | ||
// use 1 second delay to let files load | ||
@@ -454,4 +451,4 @@ setTimeout(function() { | ||
}); | ||
it('should allow bundle callbacks before definitions', function(done) { | ||
@@ -466,3 +463,3 @@ // define callback | ||
}); | ||
// use 1 second delay | ||
@@ -469,0 +466,0 @@ setTimeout(function() { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
349708
11868
288