Skip to content

Instantly share code, notes, and snippets.

@joelcox
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelcox/dfac7c58d412dab36806 to your computer and use it in GitHub Desktop.
Save joelcox/dfac7c58d412dab36806 to your computer and use it in GitHub Desktop.
Parallel promises
actions: {
submitForm: function() {
var model = this.store.createRecord('post');
this.resolveKeywords(controller.get('postKeywords')).then(function(keywords) {
model.get('keywords').pushObjects(keywords);
return model.save();
}).then(function() {
controller.transitionToRoute('post', model);
});
});
},
resolveKeywords: function(keywords) {
var controller = this;
return new Ember.RSVP.Promise(function(resolve) {
var promises = keywords.map(function(item) {
return controller.resolveSingleKeyword(item);
});
Ember.RSVP.all(promises).then(function(keywords) {
resolve(keywords);
});
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment