The answer provided by @ForbesLindesay was very helpful. However, I was using Deft 0.8.0 so there were some differences in the implementation of these promises. Here is how I got the chain to work:
_onModelLoaded: function(model) {
var promises = [];
_.each(this._customRecords, function(defect, index) {
promises.push(this._getHistoryRevisions(model, defect).then(function (revisions) {
// do stuff with revisions
}.bind(this)));
}, this);
Deft.Promise.all(promises).then(function(something) {
console.log('woot',something);
}.bind(this));
},
_getHistoryRevisions: function (model, defect) {
return this._getHistory(model, defect).then(function (record) {
return this._getRevisions(record);
}.bind(this));
},
_getHistory: function (model, defect) {
var deferred = Ext.create('Deft.promise.Deferred');
model.load(Rally.util.Ref.getOidFromRef(defect.RevisionHistory), {
scope: this,
success: function(record) {
deferred.resolve(record);
}
});
return deferred;
},
// grabbing the revisions for each defect
_getRevisions: function(record) {
var deferred = Ext.create('Deft.promise.Deferred');
record.getCollection('Revisions').load({
fetch: ['RevisionNumber', 'CreationDate', 'User', 'Description'],
scope: this,
callback: function(revisions) {
deferred.resolve(revisions);
}
});
return deferred;
},
The main difference comes from the last two functions, _getHistory
and _getRevisions
- instead of returning a new Promise(...)
, I had to create a deferred object with Ext.create('Deft.promise.Deferred');
to return and resolve within the callbacks.
Hopefully this helps anyone else with this issue of using an older version of DeftJS