]> git.za3k.com Git - flowy.git/commitdiff
Remove auto-population of defaults for collection
authorZachary Vance <vanceza@gmail.com>
Wed, 8 Apr 2015 00:48:25 +0000 (17:48 -0700)
committerZachary Vance <vanceza@gmail.com>
Wed, 8 Apr 2015 00:48:25 +0000 (17:48 -0700)
dist/flowy.js
dist/flowy.unwrapped.js
src/models/flowyDoc.js
src/views/app.js

index 697df19a33095127f60871d6aab1d1fb2aa11e55..79b826560aa61e2af3a58b84167b7917eab012c9 100644 (file)
@@ -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();
     },
index 75d80022edea1a45c6177596844c338c059d0330..4c1b6716dfddba76adcea08e28dc5ef1fd4366ce 100644 (file)
@@ -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();
     },
index 893f5a99ace0c334e06a1900b251606854a7c270..0e8508e9337c9c4cdcf526648ffdfe3c70c7df07 100644 (file)
@@ -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;
index 920b4544df67822972fa90e6c1876a265a5038bc..5e0021cef0352b41b78a076a8883d84892d2b5b2 100644 (file)
@@ -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();
     },