async-define
Advanced tools
Comparing version 3.2.0 to 3.2.1
(function (cb){ | ||
var w; | ||
var w | ||
try { | ||
w = window; | ||
w = window | ||
} catch (e) { | ||
w = global; | ||
w = global | ||
} | ||
var queue = w._async_define_queue = '_async_define_queue' in w ? w._async_define_queue : []; | ||
var cached_dependencies = w._async_define_cached_dependencies = '_async_define_cached_dependencies' in w ? w._async_define_cached_dependencies : {}; | ||
var queue = w._async_define_queue = '_async_define_queue' in w ? w._async_define_queue : [] | ||
var cached_dependencies = w._async_define_cached_dependencies = '_async_define_cached_dependencies' in w ? w._async_define_cached_dependencies : {} | ||
@@ -16,37 +16,34 @@ function getDepsArray(depNames) { | ||
len = depNames.length, | ||
deps = []; | ||
deps = [] | ||
for (i = 0; i < len; i++) { | ||
tmp = depNames[i].split('|'); | ||
depNS = tmp[0]; | ||
depProp = tmp[1]; | ||
tmp = depNames[i].split('|') | ||
depNS = tmp[0] | ||
depProp = tmp[1] | ||
if (depNS in cached_dependencies){ | ||
deps.push(depProp ? cached_dependencies[depNS][depProp] : cached_dependencies[depNS]); | ||
deps.push(depProp ? cached_dependencies[depNS][depProp] : cached_dependencies[depNS]) | ||
} else { | ||
return | ||
} | ||
else { | ||
return; | ||
} | ||
} | ||
return deps; | ||
return deps | ||
} | ||
function runThroughQueue() { | ||
while (_runThroughQueue()); | ||
} | ||
function _runThroughQueue() { | ||
var i = 0; | ||
var solvedDependency = false; | ||
while (i < queue.length){ | ||
if (execute(queue[i])){ | ||
if (queue[i].name){ | ||
solvedDependency = true; | ||
var solvedDependency = true | ||
var i | ||
while (solvedDependency){ | ||
solvedDependency = false | ||
i = 0 | ||
while (i < queue.length){ | ||
if (execute(queue[i])){ | ||
if (queue[i].name){ | ||
solvedDependency = true | ||
} | ||
queue.splice(i, 1) | ||
} else { | ||
i++ | ||
} | ||
queue.splice(i, 1); | ||
} | ||
else { | ||
i++; | ||
} | ||
} | ||
return solvedDependency; | ||
} | ||
@@ -56,16 +53,19 @@ | ||
if (item.name in cached_dependencies) { // don't execute twice | ||
return true; | ||
return true | ||
} | ||
var deps = getDepsArray(item.depNames); | ||
var exp; | ||
var deps = getDepsArray(item.depNames) | ||
var exp | ||
if (deps){ | ||
exp = item.func.apply(w, deps); | ||
if (item.name){ | ||
cached_dependencies[item.name] = exp; | ||
try { | ||
exp = item.func.apply(w, deps) | ||
if (item.name){ | ||
cached_dependencies[item.name] = exp | ||
} | ||
} catch (e) { | ||
console.log('Unable to resolve dependency "' + item.name + '". Error: ' + e.message) | ||
setTimeout(function () { throw e }, 0) | ||
} | ||
return true; | ||
return true | ||
} | ||
else { | ||
return; | ||
} | ||
return false | ||
} | ||
@@ -75,8 +75,7 @@ | ||
if (typeof o === 'function'){ | ||
return o; | ||
} | ||
else { | ||
return o | ||
} else { | ||
return function (){ | ||
return o; | ||
}; | ||
return o | ||
} | ||
} | ||
@@ -87,12 +86,11 @@ } | ||
var item = { | ||
name: typeof arguments[0] === 'string' ? arguments[0] : undefined, | ||
depNames: Array.isArray(arguments[0]) ? arguments[0] : Array.isArray(arguments[1]) ? arguments[1] : [], | ||
func: wrapObj(arguments[arguments.length - 1]) | ||
}; | ||
name: typeof arguments[0] === 'string' ? arguments[0] : undefined, | ||
depNames: Array.isArray(arguments[0]) ? arguments[0] : (Array.isArray(arguments[1]) ? arguments[1] : []), | ||
func: wrapObj(arguments[arguments.length - 1]) | ||
} | ||
if (!execute(item)){ | ||
queue.push(item); | ||
} | ||
else { | ||
queue.push(item) | ||
} else { | ||
if (item.name){ | ||
runThroughQueue(); // executed straight away, try to resolve func that depends on this | ||
runThroughQueue() // executed straight away, try to resolve func that depends on this | ||
} | ||
@@ -103,20 +101,20 @@ } | ||
function ie(moduleName, iecb) { | ||
var script = document.querySelector('script#' + moduleName); | ||
var link = document.querySelector('link#' + moduleName); | ||
var script = document.querySelector('script#' + moduleName) | ||
var link = document.querySelector('link#' + moduleName) | ||
if (!script && link) { | ||
var src = link.href; | ||
script = document.createElement('script'); | ||
script.id = moduleName; | ||
script.src = src; | ||
document.head.appendChild(script); | ||
var src = link.href | ||
script = document.createElement('script') | ||
script.id = moduleName | ||
script.src = src | ||
document.head.appendChild(script) | ||
} | ||
if (!('Promise' in w)) { | ||
return ad([moduleName], iecb); | ||
return ad([moduleName], iecb) | ||
} | ||
return new Promise(function (resolve) { | ||
ad([moduleName], resolve); | ||
ad([moduleName], resolve) | ||
}); | ||
} | ||
cb.call(w, ad, ie); | ||
cb.call(w, ad, ie) | ||
}(function (define, importExternal) { | ||
@@ -132,3 +130,3 @@ if (typeof exports === 'object'){ | ||
})); | ||
})) | ||
{ | ||
"name": "async-define", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Coordinate the execution of asynchronous scripts", | ||
@@ -29,9 +29,9 @@ "main": "lib/asyncDefine.js", | ||
"chai": "^1.10.0", | ||
"http-server": "^0.8.5", | ||
"jquery": "^2.1.4", | ||
"http-server": "^0.11.1", | ||
"jquery": "^3.3.1", | ||
"mocha": "^2.1.0", | ||
"npm-release": "^1.0.0", | ||
"react": "^0.14.3", | ||
"react-dom": "^0.14.3", | ||
"uglifyjs": "^2.4.10", | ||
"npm-release": "^1.0.0" | ||
"uglifyjs": "^2.4.10" | ||
}, | ||
@@ -38,0 +38,0 @@ "dependencies": { |
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
23117
15
373