From: Zachary Vance Date: Wed, 8 Apr 2015 00:48:25 +0000 (-0700) Subject: Remove auto-population of defaults for collection X-Git-Url: https://git.za3k.com/?a=commitdiff_plain;h=ea3351c2cd62804d296ccf468811d730a8223253;p=flowy.git Remove auto-population of defaults for collection --- diff --git a/dist/flowy.js b/dist/flowy.js index 697df19..79b8265 100644 --- a/dist/flowy.js +++ b/dist/flowy.js @@ -74,26 +74,10 @@ flowyDocDefaults = { rootId: null }; var FlowyDocModel = Backbone.Collection.extend({ initialize: function(options) { options = _.defaults({}, options, flowyDocDefaults); - this.id = options.id; - this.default = options.default; this.rootId = options.rootId; }, model: TodoModel, localStorage: new Backbone.LocalStorage("todos-backbone"), - fetch: function(options) { // TODO: Move to base class as default behavior for localStorage - // If during the initial fetch, the collection is not present, instead populate it using this.default - options = options ? _.clone(options) : {}; - var error = options.error; - var collection = this; - options.error = function(_, resp, __) { - if (resp ==="Record Not Found" && collection.default) { - var method = options.reset ? 'reset' : 'set'; - collection[method](collection.default); - } - if (error) error(collection, resp, options); - }; - Backbone.Collection.prototype.fetch.call(this, options); - }, nextOrder: function() { if (!this.length) return 1; return this.last().get('order') + 1; @@ -108,6 +92,7 @@ var FlowyDocModel = Backbone.Collection.extend({ */ var todos = new FlowyDocModel({ + /* id: "master", default: [ new TodoModel({ @@ -152,6 +137,7 @@ var todos = new FlowyDocModel({ text: "Save California", }), ], + */ }); var appDefaults = { list: todos }; @@ -161,7 +147,7 @@ var AppView = Backbone.View.extend({ options = _.defaults({}, options, appDefaults); this.listenTo(todos, 'add', this.addOne); this.listenTo(todos, 'reset', this.addAll); - this.list = options.list; + this.list = options.list || new FlowDocModel(); this.views = {}; // A list of views for each element in the collection this.list.fetch(); }, diff --git a/dist/flowy.unwrapped.js b/dist/flowy.unwrapped.js index 75d8002..4c1b671 100644 --- a/dist/flowy.unwrapped.js +++ b/dist/flowy.unwrapped.js @@ -73,26 +73,10 @@ flowyDocDefaults = { rootId: null }; var FlowyDocModel = Backbone.Collection.extend({ initialize: function(options) { options = _.defaults({}, options, flowyDocDefaults); - this.id = options.id; - this.default = options.default; this.rootId = options.rootId; }, model: TodoModel, localStorage: new Backbone.LocalStorage("todos-backbone"), - fetch: function(options) { // TODO: Move to base class as default behavior for localStorage - // If during the initial fetch, the collection is not present, instead populate it using this.default - options = options ? _.clone(options) : {}; - var error = options.error; - var collection = this; - options.error = function(_, resp, __) { - if (resp ==="Record Not Found" && collection.default) { - var method = options.reset ? 'reset' : 'set'; - collection[method](collection.default); - } - if (error) error(collection, resp, options); - }; - Backbone.Collection.prototype.fetch.call(this, options); - }, nextOrder: function() { if (!this.length) return 1; return this.last().get('order') + 1; @@ -107,6 +91,7 @@ var FlowyDocModel = Backbone.Collection.extend({ */ var todos = new FlowyDocModel({ + /* id: "master", default: [ new TodoModel({ @@ -151,6 +136,7 @@ var todos = new FlowyDocModel({ text: "Save California", }), ], + */ }); var appDefaults = { list: todos }; @@ -160,7 +146,7 @@ var AppView = Backbone.View.extend({ options = _.defaults({}, options, appDefaults); this.listenTo(todos, 'add', this.addOne); this.listenTo(todos, 'reset', this.addAll); - this.list = options.list; + this.list = options.list || new FlowDocModel(); this.views = {}; // A list of views for each element in the collection this.list.fetch(); }, diff --git a/src/models/flowyDoc.js b/src/models/flowyDoc.js index 893f5a9..0e8508e 100644 --- a/src/models/flowyDoc.js +++ b/src/models/flowyDoc.js @@ -6,26 +6,10 @@ flowyDocDefaults = { rootId: null }; var FlowyDocModel = Backbone.Collection.extend({ initialize: function(options) { options = _.defaults({}, options, flowyDocDefaults); - this.id = options.id; - this.default = options.default; this.rootId = options.rootId; }, model: TodoModel, localStorage: new Backbone.LocalStorage("todos-backbone"), - fetch: function(options) { // TODO: Move to base class as default behavior for localStorage - // If during the initial fetch, the collection is not present, instead populate it using this.default - options = options ? _.clone(options) : {}; - var error = options.error; - var collection = this; - options.error = function(_, resp, __) { - if (resp ==="Record Not Found" && collection.default) { - var method = options.reset ? 'reset' : 'set'; - collection[method](collection.default); - } - if (error) error(collection, resp, options); - }; - Backbone.Collection.prototype.fetch.call(this, options); - }, nextOrder: function() { if (!this.length) return 1; return this.last().get('order') + 1; diff --git a/src/views/app.js b/src/views/app.js index 920b454..5e0021c 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -5,6 +5,7 @@ */ var todos = new FlowyDocModel({ + /* id: "master", default: [ new TodoModel({ @@ -49,6 +50,7 @@ var todos = new FlowyDocModel({ text: "Save California", }), ], + */ }); var appDefaults = { list: todos }; @@ -58,7 +60,7 @@ var AppView = Backbone.View.extend({ options = _.defaults({}, options, appDefaults); this.listenTo(todos, 'add', this.addOne); this.listenTo(todos, 'reset', this.addAll); - this.list = options.list; + this.list = options.list || new FlowDocModel(); this.views = {}; // A list of views for each element in the collection this.list.fetch(); },