Ember controllers are promise-aware, in that the model can be a promise. For an ArrayController you could have a promise to an array, but what if you have an array containing promises?
See this JSFiddle for an example http://jsfiddle.net/7QSZ6/
Why do I need this? We have a Hypermedia (HAL) API with pagination, so if I request a collection of 500 items I get back the first 50 items, with a link to the next 50, and the total count.
I would like to create an array-like object based on Ember.Array that lazily loads consecutive pages. But since loading is async objectAt would have to return a promise that resolves when the element arrives.
Roughly in pseudocode
MyArray = Ember.Object.extend(Ember.Array({
length: 500,
retrieved: 50,
objectAt: function(i) {
if (i > this.get('retrieved')) {
retrievePageFor(i);
}
return this.get('promiseArray')[i];
},
retrievePagesFor: function(i) {
// request pages until we have a value for index i
// update 'retrieved'
// populate 'promiseArray' with promises that resolve when the data arrives
}
}));
Update:
One way is to do it "manually" by using PromiseProxyMixin, e.g. http://jsfiddle.net/Au7LC/1/