loadjs
Advanced tools
Comparing version 3.2.1 to 3.3.0
{ | ||
"name": "loadjs", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "authors": [ |
# LoadJS Changelog | ||
## 3.3.0 - January 9, 2007 | ||
* Added reset() method to reset dependency trackers | ||
## 3.2.1 - December 18, 2016 | ||
@@ -4,0 +8,0 @@ |
@@ -37,3 +37,3 @@ loadjs = (function () { | ||
}; | ||
// register callback | ||
@@ -65,3 +65,3 @@ while (i--) { | ||
if (!bundleId) return; | ||
var q = bundleCallbackQueue[bundleId]; | ||
@@ -74,3 +74,3 @@ | ||
if (!q) return; | ||
// empty callback queue | ||
@@ -159,3 +159,3 @@ while (q.length) { | ||
paths = paths.push ? paths : [paths]; | ||
var numWaiting = paths.length, | ||
@@ -166,3 +166,3 @@ x = numWaiting, | ||
i; | ||
// define callback function | ||
@@ -199,3 +199,3 @@ fn = function(path, result, defaultPrevented) { | ||
args; | ||
// bundleId (if string) | ||
@@ -210,3 +210,3 @@ if (arg1 && arg1.trim) bundleId = arg1; | ||
if (bundleId in bundleIdCache) { | ||
throw new Error("LoadJS"); | ||
throw "LoadJS"; | ||
} else { | ||
@@ -255,2 +255,12 @@ bundleIdCache[bundleId] = true; | ||
/** | ||
* Reset loadjs dependencies statuses | ||
*/ | ||
loadjs.reset = function reset() { | ||
bundleIdCache = {}; | ||
bundleResultCache = {}; | ||
bundleCallbackQueue = {}; | ||
}; | ||
// export | ||
@@ -257,0 +267,0 @@ return loadjs; |
@@ -1,1 +0,1 @@ | ||
loadjs=function(){function e(e,n){e=e.push?e:[e];var t,r,o,i,c=[],s=e.length,h=s;for(t=function(e,t){t.length&&c.push(e),h--,h||n(c)};s--;)r=e[s],o=u[r],o?t(r,o):(i=f[r]=f[r]||[],i.push(t))}function n(e,n){if(e){var t=f[e];if(u[e]=n,t)for(;t.length;)t[0](e,n),t.splice(0,1)}}function t(e,n,r,o){var c,u,f=document,s=r.async,h=(r.numRetries||0)+1,a=r.before||i;o=o||0,/\.css$/.test(e)?(c=!0,u=f.createElement("link"),u.rel="stylesheet",u.href=e):(u=f.createElement("script"),u.src=e,u.async=void 0===s||s),u.onload=u.onerror=u.onbeforeload=function(i){var f=i.type[0];if(c&&"hideFocus"in u)try{u.sheet.cssText.length||(f="e")}catch(e){f="e"}return"e"==f&&(o+=1,o<h)?t(e,n,r,o):void n(e,f,i.defaultPrevented)},a(e,u),f.head.appendChild(u)}function r(e,n,r){e=e.push?e:[e];var o,i,c=e.length,u=c,f=[];for(o=function(e,t,r){if("e"==t&&f.push(e),"b"==t){if(!r)return;f.push(e)}c--,c||n(f)},i=0;i<u;i++)t(e[i],o,r)}function o(e,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(e,function(e){e.length?(f.error||i)(e):(f.success||i)(),n(u,e)},f)}var i=function(){},c={},u={},f={};return o.ready=function(n,t){return e(n,function(e){e.length?(t.error||i)(e):(t.success||i)()}),o},o.done=function(e){n(e,[])},o}(); | ||
loadjs=function(){function e(e,n){e=e.push?e:[e];var t,r,o,i,c=[],s=e.length,h=s;for(t=function(e,t){t.length&&c.push(e),h--,h||n(c)};s--;)r=e[s],o=u[r],o?t(r,o):(i=f[r]=f[r]||[],i.push(t))}function n(e,n){if(e){var t=f[e];if(u[e]=n,t)for(;t.length;)t[0](e,n),t.splice(0,1)}}function t(e,n,r,o){var c,u,f=document,s=r.async,h=(r.numRetries||0)+1,a=r.before||i;o=o||0,/\.css$/.test(e)?(c=!0,u=f.createElement("link"),u.rel="stylesheet",u.href=e):(u=f.createElement("script"),u.src=e,u.async=void 0===s||s),u.onload=u.onerror=u.onbeforeload=function(i){var f=i.type[0];if(c&&"hideFocus"in u)try{u.sheet.cssText.length||(f="e")}catch(e){f="e"}return"e"==f&&(o+=1,o<h)?t(e,n,r,o):void n(e,f,i.defaultPrevented)},a(e,u),f.head.appendChild(u)}function r(e,n,r){e=e.push?e:[e];var o,i,c=e.length,u=c,f=[];for(o=function(e,t,r){if("e"==t&&f.push(e),"b"==t){if(!r)return;f.push(e)}c--,c||n(f)},i=0;i<u;i++)t(e[i],o,r)}function o(e,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in c)throw"LoadJS";c[u]=!0}r(e,function(e){e.length?(f.error||i)(e):(f.success||i)(),n(u,e)},f)}var i=function(){},c={},u={},f={};return o.ready=function(n,t){return e(n,function(e){e.length?(t.error||i)(e):(t.success||i)()}),o},o.done=function(e){n(e,[])},o.reset=function(){c={},u={},f={}},o}(); |
@@ -45,3 +45,3 @@ (function(root, factory) { | ||
}; | ||
// register callback | ||
@@ -73,3 +73,3 @@ while (i--) { | ||
if (!bundleId) return; | ||
var q = bundleCallbackQueue[bundleId]; | ||
@@ -82,3 +82,3 @@ | ||
if (!q) return; | ||
// empty callback queue | ||
@@ -167,3 +167,3 @@ while (q.length) { | ||
paths = paths.push ? paths : [paths]; | ||
var numWaiting = paths.length, | ||
@@ -174,3 +174,3 @@ x = numWaiting, | ||
i; | ||
// define callback function | ||
@@ -207,3 +207,3 @@ fn = function(path, result, defaultPrevented) { | ||
args; | ||
// bundleId (if string) | ||
@@ -218,3 +218,3 @@ if (arg1 && arg1.trim) bundleId = arg1; | ||
if (bundleId in bundleIdCache) { | ||
throw new Error("LoadJS"); | ||
throw "LoadJS"; | ||
} else { | ||
@@ -263,2 +263,12 @@ bundleIdCache[bundleId] = true; | ||
/** | ||
* Reset loadjs dependencies statuses | ||
*/ | ||
loadjs.reset = function reset() { | ||
bundleIdCache = {}; | ||
bundleResultCache = {}; | ||
bundleCallbackQueue = {}; | ||
}; | ||
// export | ||
@@ -265,0 +275,0 @@ return loadjs; |
@@ -37,3 +37,3 @@ loadjs = (function () { | ||
}; | ||
// register callback | ||
@@ -65,3 +65,3 @@ while (i--) { | ||
if (!bundleId) return; | ||
var q = bundleCallbackQueue[bundleId]; | ||
@@ -74,3 +74,3 @@ | ||
if (!q) return; | ||
// empty callback queue | ||
@@ -159,3 +159,3 @@ while (q.length) { | ||
paths = paths.push ? paths : [paths]; | ||
var numWaiting = paths.length, | ||
@@ -166,3 +166,3 @@ x = numWaiting, | ||
i; | ||
// define callback function | ||
@@ -199,3 +199,3 @@ fn = function(path, result, defaultPrevented) { | ||
args; | ||
// bundleId (if string) | ||
@@ -210,3 +210,3 @@ if (arg1 && arg1.trim) bundleId = arg1; | ||
if (bundleId in bundleIdCache) { | ||
throw new Error("LoadJS"); | ||
throw "LoadJS"; | ||
} else { | ||
@@ -255,2 +255,12 @@ bundleIdCache[bundleId] = true; | ||
/** | ||
* Reset loadjs dependencies statuses | ||
*/ | ||
loadjs.reset = function reset() { | ||
bundleIdCache = {}; | ||
bundleResultCache = {}; | ||
bundleCallbackQueue = {}; | ||
}; | ||
// export | ||
@@ -257,0 +267,0 @@ return loadjs; |
@@ -1,1 +0,1 @@ | ||
loadjs=function(){function e(e,n){e=e.push?e:[e];var t,r,o,i,c=[],s=e.length,h=s;for(t=function(e,t){t.length&&c.push(e),h--,h||n(c)};s--;)r=e[s],o=u[r],o?t(r,o):(i=f[r]=f[r]||[],i.push(t))}function n(e,n){if(e){var t=f[e];if(u[e]=n,t)for(;t.length;)t[0](e,n),t.splice(0,1)}}function t(e,n,r,o){var c,u,f=document,s=r.async,h=(r.numRetries||0)+1,a=r.before||i;o=o||0,/\.css$/.test(e)?(c=!0,u=f.createElement("link"),u.rel="stylesheet",u.href=e):(u=f.createElement("script"),u.src=e,u.async=void 0===s||s),u.onload=u.onerror=u.onbeforeload=function(i){var f=i.type[0];if(c&&"hideFocus"in u)try{u.sheet.cssText.length||(f="e")}catch(e){f="e"}return"e"==f&&(o+=1,o<h)?t(e,n,r,o):void n(e,f,i.defaultPrevented)},a(e,u),f.head.appendChild(u)}function r(e,n,r){e=e.push?e:[e];var o,i,c=e.length,u=c,f=[];for(o=function(e,t,r){if("e"==t&&f.push(e),"b"==t){if(!r)return;f.push(e)}c--,c||n(f)},i=0;i<u;i++)t(e[i],o,r)}function o(e,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(e,function(e){e.length?(f.error||i)(e):(f.success||i)(),n(u,e)},f)}var i=function(){},c={},u={},f={};return o.ready=function(n,t){return e(n,function(e){e.length?(t.error||i)(e):(t.success||i)()}),o},o.done=function(e){n(e,[])},o}(); | ||
loadjs=function(){function e(e,n){e=e.push?e:[e];var t,r,o,i,c=[],s=e.length,h=s;for(t=function(e,t){t.length&&c.push(e),h--,h||n(c)};s--;)r=e[s],o=u[r],o?t(r,o):(i=f[r]=f[r]||[],i.push(t))}function n(e,n){if(e){var t=f[e];if(u[e]=n,t)for(;t.length;)t[0](e,n),t.splice(0,1)}}function t(e,n,r,o){var c,u,f=document,s=r.async,h=(r.numRetries||0)+1,a=r.before||i;o=o||0,/\.css$/.test(e)?(c=!0,u=f.createElement("link"),u.rel="stylesheet",u.href=e):(u=f.createElement("script"),u.src=e,u.async=void 0===s||s),u.onload=u.onerror=u.onbeforeload=function(i){var f=i.type[0];if(c&&"hideFocus"in u)try{u.sheet.cssText.length||(f="e")}catch(e){f="e"}return"e"==f&&(o+=1,o<h)?t(e,n,r,o):void n(e,f,i.defaultPrevented)},a(e,u),f.head.appendChild(u)}function r(e,n,r){e=e.push?e:[e];var o,i,c=e.length,u=c,f=[];for(o=function(e,t,r){if("e"==t&&f.push(e),"b"==t){if(!r)return;f.push(e)}c--,c||n(f)},i=0;i<u;i++)t(e[i],o,r)}function o(e,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in c)throw"LoadJS";c[u]=!0}r(e,function(e){e.length?(f.error||i)(e):(f.success||i)(),n(u,e)},f)}var i=function(){},c={},u={},f={};return o.ready=function(n,t){return e(n,function(e){e.length?(t.error||i)(e):(t.success||i)()}),o},o.done=function(e){n(e,[])},o.reset=function(){c={},u={},f={}},o}(); |
{ | ||
"name": "loadjs", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Tiny async loader for modern browsers", |
@@ -5,3 +5,3 @@ # LoadJS | ||
LoadJS is a tiny async loader for modern browsers (710 bytes). | ||
LoadJS is a tiny async loader for modern browsers (711 bytes). | ||
@@ -15,3 +15,3 @@ [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) | ||
LoadJS is based on the excellent <a href="https://github.com/ded/script.js">$script</a> library by <a href="https://github.com/ded">Dustin Diaz</a>. We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 710 bytes (minified + gzipped). | ||
LoadJS is based on the excellent [$script](https://github.com/ded/script.js) library by [Dustin Diaz](https://github.com/ded). We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 711 bytes (minified + gzipped). | ||
@@ -192,19 +192,22 @@ Here's an example of what you can do with LoadJS: | ||
```javascript | ||
loadjs.ready('my-awesome-plugin', { | ||
loadjs.ready(['dependency1', 'dependency2'], { | ||
success: function() { | ||
myAwesomePlugin(); | ||
// run code after dependencies have been met | ||
} | ||
}); | ||
loadjs.ready('jquery', { | ||
success: function() { | ||
// plugin requires jquery | ||
window.myAwesomePlugin = function() { | ||
if (!window.jQuery) throw "jQuery is missing!"; | ||
}; | ||
function fn1() { | ||
loadjs.done('dependency1'); | ||
} | ||
function fn2() { | ||
loadjs.done('dependency2'); | ||
} | ||
``` | ||
// plugin is done loading | ||
loadjs.done('my-awesome-plugin'); | ||
} | ||
}); | ||
1. Reset dependency trackers | ||
```javascript | ||
loadjs.reset() | ||
``` | ||
@@ -235,4 +238,4 @@ | ||
* nodejs (http://nodejs.org/) | ||
* npm (https://www.npmjs.org/) | ||
* [nodejs](http://nodejs.org/) | ||
* [npm](https://www.npmjs.org/) | ||
* http-server (via npm) | ||
@@ -266,3 +269,3 @@ | ||
Then visit http://localhost:3000/examples | ||
Then visit [http://localhost:3000/examples](http://localhost:3000/examples) | ||
@@ -285,3 +288,3 @@ 1. Build distribution files | ||
Then visit http://localhost:3000/test | ||
Then visit [http://localhost:3000/test](http://localhost:3000/test) | ||
@@ -288,0 +291,0 @@ 1. Build all files |
@@ -36,3 +36,3 @@ /** | ||
}; | ||
// register callback | ||
@@ -64,3 +64,3 @@ while (i--) { | ||
if (!bundleId) return; | ||
var q = bundleCallbackQueue[bundleId]; | ||
@@ -73,3 +73,3 @@ | ||
if (!q) return; | ||
// empty callback queue | ||
@@ -158,3 +158,3 @@ while (q.length) { | ||
paths = paths.push ? paths : [paths]; | ||
var numWaiting = paths.length, | ||
@@ -165,3 +165,3 @@ x = numWaiting, | ||
i; | ||
// define callback function | ||
@@ -198,3 +198,3 @@ fn = function(path, result, defaultPrevented) { | ||
args; | ||
// bundleId (if string) | ||
@@ -209,3 +209,3 @@ if (arg1 && arg1.trim) bundleId = arg1; | ||
if (bundleId in bundleIdCache) { | ||
throw new Error("LoadJS"); | ||
throw "LoadJS"; | ||
} else { | ||
@@ -254,3 +254,13 @@ bundleIdCache[bundleId] = true; | ||
/** | ||
* Reset loadjs dependencies statuses | ||
*/ | ||
loadjs.reset = function reset() { | ||
bundleIdCache = {}; | ||
bundleResultCache = {}; | ||
bundleCallbackQueue = {}; | ||
}; | ||
// export | ||
return loadjs; |
@@ -37,3 +37,3 @@ loadjs = (function () { | ||
}; | ||
// register callback | ||
@@ -65,3 +65,3 @@ while (i--) { | ||
if (!bundleId) return; | ||
var q = bundleCallbackQueue[bundleId]; | ||
@@ -74,3 +74,3 @@ | ||
if (!q) return; | ||
// empty callback queue | ||
@@ -159,3 +159,3 @@ while (q.length) { | ||
paths = paths.push ? paths : [paths]; | ||
var numWaiting = paths.length, | ||
@@ -166,3 +166,3 @@ x = numWaiting, | ||
i; | ||
// define callback function | ||
@@ -199,3 +199,3 @@ fn = function(path, result, defaultPrevented) { | ||
args; | ||
// bundleId (if string) | ||
@@ -210,3 +210,3 @@ if (arg1 && arg1.trim) bundleId = arg1; | ||
if (bundleId in bundleIdCache) { | ||
throw new Error("LoadJS"); | ||
throw "LoadJS"; | ||
} else { | ||
@@ -255,2 +255,12 @@ bundleIdCache[bundleId] = true; | ||
/** | ||
* Reset loadjs dependencies statuses | ||
*/ | ||
loadjs.reset = function reset() { | ||
bundleIdCache = {}; | ||
bundleResultCache = {}; | ||
bundleCallbackQueue = {}; | ||
}; | ||
// export | ||
@@ -257,0 +267,0 @@ return loadjs; |
@@ -1,1 +0,1 @@ | ||
loadjs=function(){function e(e,n){e=e.push?e:[e];var t,r,o,i,c=[],s=e.length,h=s;for(t=function(e,t){t.length&&c.push(e),h--,h||n(c)};s--;)r=e[s],o=u[r],o?t(r,o):(i=f[r]=f[r]||[],i.push(t))}function n(e,n){if(e){var t=f[e];if(u[e]=n,t)for(;t.length;)t[0](e,n),t.splice(0,1)}}function t(e,n,r,o){var c,u,f=document,s=r.async,h=(r.numRetries||0)+1,a=r.before||i;o=o||0,/\.css$/.test(e)?(c=!0,u=f.createElement("link"),u.rel="stylesheet",u.href=e):(u=f.createElement("script"),u.src=e,u.async=void 0===s||s),u.onload=u.onerror=u.onbeforeload=function(i){var f=i.type[0];if(c&&"hideFocus"in u)try{u.sheet.cssText.length||(f="e")}catch(e){f="e"}return"e"==f&&(o+=1,o<h)?t(e,n,r,o):void n(e,f,i.defaultPrevented)},a(e,u),f.head.appendChild(u)}function r(e,n,r){e=e.push?e:[e];var o,i,c=e.length,u=c,f=[];for(o=function(e,t,r){if("e"==t&&f.push(e),"b"==t){if(!r)return;f.push(e)}c--,c||n(f)},i=0;i<u;i++)t(e[i],o,r)}function o(e,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(e,function(e){e.length?(f.error||i)(e):(f.success||i)(),n(u,e)},f)}var i=function(){},c={},u={},f={};return o.ready=function(n,t){return e(n,function(e){e.length?(t.error||i)(e):(t.success||i)()}),o},o.done=function(e){n(e,[])},o}(); | ||
loadjs=function(){function e(e,n){e=e.push?e:[e];var t,r,o,i,c=[],s=e.length,h=s;for(t=function(e,t){t.length&&c.push(e),h--,h||n(c)};s--;)r=e[s],o=u[r],o?t(r,o):(i=f[r]=f[r]||[],i.push(t))}function n(e,n){if(e){var t=f[e];if(u[e]=n,t)for(;t.length;)t[0](e,n),t.splice(0,1)}}function t(e,n,r,o){var c,u,f=document,s=r.async,h=(r.numRetries||0)+1,a=r.before||i;o=o||0,/\.css$/.test(e)?(c=!0,u=f.createElement("link"),u.rel="stylesheet",u.href=e):(u=f.createElement("script"),u.src=e,u.async=void 0===s||s),u.onload=u.onerror=u.onbeforeload=function(i){var f=i.type[0];if(c&&"hideFocus"in u)try{u.sheet.cssText.length||(f="e")}catch(e){f="e"}return"e"==f&&(o+=1,o<h)?t(e,n,r,o):void n(e,f,i.defaultPrevented)},a(e,u),f.head.appendChild(u)}function r(e,n,r){e=e.push?e:[e];var o,i,c=e.length,u=c,f=[];for(o=function(e,t,r){if("e"==t&&f.push(e),"b"==t){if(!r)return;f.push(e)}c--,c||n(f)},i=0;i<u;i++)t(e[i],o,r)}function o(e,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in c)throw"LoadJS";c[u]=!0}r(e,function(e){e.length?(f.error||i)(e):(f.success||i)(),n(u,e)},f)}var i=function(){},c={},u={},f={};return o.ready=function(n,t){return e(n,function(e){e.length?(t.error||i)(e):(t.success||i)()}),o},o.done=function(e){n(e,[])},o.reset=function(){c={},u={},f={}},o}(); |
@@ -17,2 +17,5 @@ /** | ||
pathsLoaded = {}; | ||
// reset loadjs dependencies | ||
loadjs.reset(); | ||
}); | ||
@@ -108,3 +111,3 @@ | ||
paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; | ||
// run tests sequentially | ||
@@ -121,10 +124,10 @@ var testFn = function(paths) { | ||
var f2 = paths[1].replace('assets/', ''); | ||
// check load order | ||
assert.isTrue(pathsLoaded[f1]); | ||
assert.isFalse(pathsLoaded[f2]); | ||
// increment tests | ||
numCompleted += 1; | ||
if (numCompleted === numTests) { | ||
@@ -136,3 +139,3 @@ // exit | ||
pathsLoaded = {}; | ||
// run test again | ||
@@ -146,3 +149,3 @@ paths.reverse(); | ||
}; | ||
// run tests | ||
@@ -315,10 +318,10 @@ testFn(paths); | ||
// define bundle | ||
loadjs(['assets/file1.js'], 'bundle3'); | ||
loadjs(['assets/file1.js'], 'bundle'); | ||
// define bundle again | ||
var fn = function() { | ||
loadjs(['assets/file1.js'], 'bundle3'); | ||
loadjs(['assets/file1.js'], 'bundle'); | ||
}; | ||
expect(fn).to.throw(Error, "LoadJS"); | ||
expect(fn).to.throw("LoadJS"); | ||
}); | ||
@@ -328,3 +331,3 @@ | ||
it('should create a bundle id and a callback inline', function(done) { | ||
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', { | ||
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle', { | ||
success: function() { | ||
@@ -345,7 +348,7 @@ assert.equal(pathsLoaded['file1.js'], true); | ||
// define bundles | ||
loadjs('assets/file1.js', 'bundle5'); | ||
loadjs('assets/file2.js', 'bundle6'); | ||
loadjs('assets/file1.js', 'bundle1'); | ||
loadjs('assets/file2.js', 'bundle2'); | ||
loadjs | ||
.ready('bundle5', { | ||
.ready('bundle1', { | ||
success: function() { | ||
@@ -355,3 +358,3 @@ assert.equal(pathsLoaded['file1.js'], true); | ||
}}) | ||
.ready('bundle6', { | ||
.ready('bundle2', { | ||
success: function() { | ||
@@ -366,6 +369,6 @@ assert.equal(pathsLoaded['file2.js'], true); | ||
it('should handle multiple dependencies', function(done) { | ||
loadjs('assets/file1.js', 'bundle7'); | ||
loadjs('assets/file2.js', 'bundle8'); | ||
loadjs('assets/file1.js', 'bundle1'); | ||
loadjs('assets/file2.js', 'bundle2'); | ||
loadjs.ready(['bundle7', 'bundle8'], { | ||
loadjs.ready(['bundle1', 'bundle2'], { | ||
success: function() { | ||
@@ -381,6 +384,6 @@ assert.equal(pathsLoaded['file1.js'], true); | ||
it('should error on missing depdendencies', function(done) { | ||
loadjs('assets/file1.js', 'bundle9'); | ||
loadjs('assets/file-doesntexist.js', 'bundle10'); | ||
loadjs('assets/file1.js', 'bundle1'); | ||
loadjs('assets/file-doesntexist.js', 'bundle2'); | ||
loadjs.ready(['bundle9', 'bundle10'], { | ||
loadjs.ready(['bundle1', 'bundle2'], { | ||
success: function() { | ||
@@ -392,3 +395,3 @@ throw "Executed success callback"; | ||
assert.equal(depsNotFound.length, 1); | ||
assert.equal(depsNotFound[0], 'bundle10'); | ||
assert.equal(depsNotFound[0], 'bundle2'); | ||
done(); | ||
@@ -402,3 +405,3 @@ } | ||
// add handler | ||
loadjs.ready('plugin1', { | ||
loadjs.ready('plugin', { | ||
success: function() { | ||
@@ -410,3 +413,3 @@ done(); | ||
// execute done | ||
loadjs.done('plugin1'); | ||
loadjs.done('plugin'); | ||
}); | ||
@@ -417,6 +420,6 @@ | ||
// execute done | ||
loadjs.done('plugin2'); | ||
loadjs.done('plugin'); | ||
// add handler | ||
loadjs.ready('plugin2', { | ||
loadjs.ready('plugin', { | ||
success: function() { | ||
@@ -431,7 +434,7 @@ done(); | ||
// define bundle | ||
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); | ||
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); | ||
// use 1 second delay to let files load | ||
setTimeout(function() { | ||
loadjs.ready('bundle1', { | ||
loadjs.ready('bundle', { | ||
success: function() { | ||
@@ -449,3 +452,3 @@ assert.equal(pathsLoaded['file1.js'], true); | ||
// define callback | ||
loadjs.ready('bundle2', { | ||
loadjs.ready('bundle', { | ||
success: function() { | ||
@@ -460,6 +463,19 @@ assert.equal(pathsLoaded['file1.js'], true); | ||
setTimeout(function() { | ||
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); | ||
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); | ||
}, 1000); | ||
}); | ||
it('should reset dependencies statuses', function() { | ||
loadjs(['assets/file1.js'], 'cleared'); | ||
loadjs.reset(); | ||
// define bundle again | ||
var fn = function() { | ||
loadjs(['assets/file1.js'], 'cleared'); | ||
}; | ||
expect(fn).not.to.throw("LoadJS"); | ||
}); | ||
}); | ||
}); |
350798
11919
291