Skip to content

Instantly share code, notes, and snippets.

@jnhuynh
Last active August 29, 2015 14:11
Show Gist options
  • Save jnhuynh/897b566f40ce06a03ec8 to your computer and use it in GitHub Desktop.
Save jnhuynh/897b566f40ce06a03ec8 to your computer and use it in GitHub Desktop.
Ember.Route.extend({
model: function() {
var promises = {
apiCall1: new Ember.RSVP.Promise(function(resolve, reject) {
// make api call 1
}),
apiCall2: new Ember.RSVP.Promise(function(resolve, reject) {
// make api call 2
})
};
// Free to do some shaping/mapping here to the primises hash properties by attaching then clauses.
var allMyData = new Ember.RSVP.hash(promises);
allMyData.then(function(results) {
// apiCall1 and apiCall2 will be available, except their result will be whatever your API responded with.
// Do what you will to shape/map your data to a model.
// Return it here
});
return allMyData;
},
setupController: function(controller, model) {
// by this point your model will by the result of the the shaping/mapping you did in your then resolve callback.
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment