-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
Description
What would you say if add ability to pass to Collection methods not only plain objects, arrays and models, but also promise. Just add code like this to each method
add: function(models, options) {
//...
if (typeof models.then === 'function') {
var self = this;
return models.then(function (models) {
return self.set(models, options);
});
}
//..
}
and so we can do
users.add($.get('/users'));
very useful if you decided to change some of your methods from sync to async like
User = Model.extend({
getProducts: function () {
// was
return products.where({user_id: this.get('id')});
// become
return $.get('/products', {user_id: this.get('id')});
}
});
// but code same for sync and async
bag.add(user.getProducts());