PageRenderTime 0ms CodeModel.GetById 50ms app.highlight 2ms RepoModel.GetById 18ms 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
 1Backbone.Collection.prototype.save = function() {
 2
 3	console.log("Saving collection");
 4
 5	/*
 6		Possibilities:
 7		1. Send newly added models, updated models and deleted models in different requests
 8			- Requires tracking of deleted models
 9		2. Send all models but separate them into new, updated, deleted
10		3. Send the whole collection as-is and let the server decide what to do
11			- How would we deal with knowing what ones to delete?
12	*/
13
14	var models = {added: [], updated: [], removed: []};
15
16	this.models.forEach(function(model) {
17
18		if (model.isNew()) {
19
20			models.added.push(model);
21
22		} else if (model.hasChanged()) {
23
24			models.updated.push(model);
25
26		}
27
28	});
29
30	/*} else if (model.hasChanged()) {
31
32			models.removed.push(model);*/
33
34};
35
36/*Backbone.Collection.extend({
37	remove: function(models, options) {
38		console.log("Removed:", models);
39		Backbone.Collection.prototype.remove.call(this, models, options);
40	}
41});*/