Last active
August 29, 2015 14:15
-
-
Save joelcox/dfac7c58d412dab36806 to your computer and use it in GitHub Desktop.
Parallel promises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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