-
Notifications
You must be signed in to change notification settings - Fork 395
Using with Dojo
when.js works great with Dojo's Deferred. Not only does when()
accept a Dojo Deferred, all of the extra goodies that handle joining promise arrays, like when.all()
, when.map()
, when.reduce()
, etc do too. They'll even work with a mixed array of Dojo Deferred (or deferred.promise
), when.js Promise or Deferred, any other Promises/A promise, and immediate values. This is one of the advantages of when()
(read more here).
Similarly, dojo.when()
(aka Deferred.when()
in Dojo 1.7) can accept a when.js Promise. When you pass a when.js Promise to dojo.when()
, it will also return a when.js Promise.
One key difference between when()
and dojo.when()
, is that when()
is guaranteed to return a Promises/A compliant promise in all cases, but dojo.when()
is not. dojo.when()
is only guaranteed to return a Promises/A promise when it is passed one as its input.
Here is a Dojo 1.7 Builder profile that you can use to include when.js in a build with Dojo. Thanks to bryanforbes for contributing this profile!
// Save this as when.profile.js in the when.js dir
var profile = (function(){
var testRE = /^when\/test\//;
return {
resourceTags: {
test: function(filename, mid){
// Tag test files as such
return testRE.test(mid);
},
amd: function(filename, mid){
// Tag the module as AMD so it doesn't get
// wrapped by the Dojo builder
return mid == "when/when" || mid == "when";
},
copyOnly: function(filename, mid){
// Don't process package.json
return mid == "when/package.json";
}
}
};
})();