async-define
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -43,2 +43,5 @@ (function (w){ | ||
function execute (item){ | ||
if (item.name in cached_dependencies) { // don't execute twice | ||
return true; | ||
} | ||
var deps = getDepsArray(item.depNames); | ||
@@ -45,0 +48,0 @@ var exp; |
{ | ||
"name": "async-define", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Coordinate the execution of asynchronous scripts", | ||
@@ -5,0 +5,0 @@ "main": "lib/asyncDefine.js", |
@@ -44,5 +44,18 @@ asyncDefine | ||
``` | ||
It is also protecting you for executing the same common libraries twice. For example: | ||
```js | ||
defineAsync('script1', function (){ | ||
// will I be executed ? | ||
return; | ||
}); | ||
defineAsync('script1', function (){ | ||
// will I be executed ? | ||
return; | ||
}); | ||
``` | ||
In the previous example only one of these will be executed. | ||
Syntax | ||
------ | ||
The syntax resemble a lot AMD (http://requirejs.org/docs/api.html#define). There is only one function: | ||
The syntax resembles a lot AMD (http://requirejs.org/docs/api.html#define). There is only one function: | ||
```js | ||
@@ -131,1 +144,2 @@ defineAsync(name, [array of dependencies], func); | ||
All will be downloaded asynchronously with the maximum performances! | ||
There is also a transformer available https://github.com/tes/browserify-async-define |
@@ -62,3 +62,26 @@ var asyncDefine = require('../lib/asyncDefine'); | ||
it("mustn't execute the same dep twice", function (done) { | ||
var counter = 0; | ||
setTimeout(function (){ | ||
asyncDefine("duplicated", function (){ | ||
counter++; | ||
return "duplicated1"; | ||
}); | ||
}, 10); | ||
setTimeout(function (){ | ||
asyncDefine("duplicated", function (hello){ | ||
counter++; | ||
return "duplicated2"; | ||
}); | ||
}, 20); | ||
setTimeout(function (){ | ||
assert.equal(counter, 1); | ||
done(); | ||
}, 50); | ||
}); | ||
}); |
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
11477
181
143