-
Notifications
You must be signed in to change notification settings - Fork 56
Promises API
[Back to Additional Features] (Additional-Features)
If you aren’t familiar with Promises, perhaps the Wikipedia definition will help:
In computer science, future, promise, and delay refer to constructs used for synchronizing in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is yet incomplete.
Put another way, a Promise represents a future value that will eventually be returned asynchronously. In the JavaScript world, the folks at CommonJS have proposed a specification called Promises/A, which is what the DeftJS Promise API is modeled upon.
In it's most basic and common form, a method will create and return a Promise like this:
loadCompanies: function() {
var deferred = Ext.create('Deft.Deferred');
this.companyStore.load({
callback: function(records, operation, success) {
if (success) {
return deferred.resolve(records);
} else {
return deferred.reject("Error loading Companies.");
}
}
});
return deferred.promise;
}