PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/v1/Backbone.Collection.save.js

https://github.com/adrianblynch/Backbone.Collection.save
JavaScript | 41 lines | 11 code | 13 blank | 17 comment | 3 complexity | 0ffc1486ad779c7c44bc77eae2dfce5f MD5 | raw file
  1. Backbone.Collection.prototype.save = function() {
  2. console.log("Saving collection");
  3. /*
  4. Possibilities:
  5. 1. Send newly added models, updated models and deleted models in different requests
  6. - Requires tracking of deleted models
  7. 2. Send all models but separate them into new, updated, deleted
  8. 3. Send the whole collection as-is and let the server decide what to do
  9. - How would we deal with knowing what ones to delete?
  10. */
  11. var models = {added: [], updated: [], removed: []};
  12. this.models.forEach(function(model) {
  13. if (model.isNew()) {
  14. models.added.push(model);
  15. } else if (model.hasChanged()) {
  16. models.updated.push(model);
  17. }
  18. });
  19. /*} else if (model.hasChanged()) {
  20. models.removed.push(model);*/
  21. };
  22. /*Backbone.Collection.extend({
  23. remove: function(models, options) {
  24. console.log("Removed:", models);
  25. Backbone.Collection.prototype.remove.call(this, models, options);
  26. }
  27. });*/