I'm new to promises, but I've looked at some examples using Deft.js and I'm wondering why my basic example isn't working.
Looking at This site, I thought the .done() function should work, but I keep getting errors.
Here is my code:
onScopeChange: function(scope) {
var promise = this.loadStories(scope).then({
success: function(records) {
console.log(records);
},
failure: function(error) {
alert(error);
}
}).always(function() {
// Do something whether call succeeded or failed
console.log('this should always appear');
}).done();
},
loadStories: function(scope) {
var deferred = Ext.create('Deft.promise.Deferred');
Ext.create('Rally.data.wsapi.Store', {
autoLoad: true,
model: 'UserStory',
fetch: ['FormattedID', 'Name', 'ScheduleState','RevisionHistory'],
filters: [scope.getQueryFilter()],
listeners: {
load: function(me, records, success) {
this._onStoriesLoaded(deferred, records, success);
},
scope: this
}
});
return deferred.promise;
},
_onStoriesLoaded: function(deferred, records, success) {
console.log('stories loaded ...');
if (success) {
deferred.resolve(records);
} else {
deferred.reject("Error loading stories");
}
}
This is just a very basic example where 'Rally.data.wsapi.Store' leads to asynchronous callbacks.
My question is only why the .done() does not work - I keep getting an error saying:
TypeError: Object [object Object] has no method 'done'
Which implies that my 'promise' object is not actually a Deft Promise object, right?
Are you sure you're using the last version of Deft? On the page you're linking, he says
done()will be integrated into Deft v0.9.I've tested the following code against Deft v0.9.1, and it's working exactly as intended:
Gives me:
I'm not told
done()is undefined, and without thedone()call, the runtime error is swallowed.(By the way, thanks for bringing to my attention that Deft has evolved... The muting of errors has been something that once gave me some great sorrows!)