From b3ac590a586b121a72d24f8cbdcd8108b2910265 Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Wed, 4 Jul 2012 15:00:13 +0100 Subject: [PATCH] [model][s]: add a constructor with the name of the object for better debugging. --- src/model.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/model.js b/src/model.js index 5a9a848a..4fa763c1 100644 --- a/src/model.js +++ b/src/model.js @@ -6,7 +6,9 @@ this.recline.Model = this.recline.Model || {}; // ## Dataset my.Dataset = Backbone.Model.extend({ - __type__: 'Dataset', + constructor: function Dataset() { + Backbone.Model.prototype.constructor.apply(this, arguments); + }, // ### initialize initialize: function() { @@ -331,7 +333,10 @@ my.Dataset.restore = function(state) { // // A single entry or row in the dataset my.Record = Backbone.Model.extend({ - __type__: 'Record', + constructor: function Record() { + Backbone.Model.prototype.constructor.apply(this, arguments); + }, + initialize: function() { _.bindAll(this, 'getFieldValue'); }, @@ -369,14 +374,21 @@ my.Record = Backbone.Model.extend({ destroy: function() { this.trigger('destroy', this); } }); + // ## A Backbone collection of Records my.RecordList = Backbone.Collection.extend({ - __type__: 'RecordList', + constructor: function RecordList() { + Backbone.Collection.prototype.constructor.apply(this, arguments); + }, model: my.Record }); + // ## A Field (aka Column) on a Dataset my.Field = Backbone.Model.extend({ + constructor: function Field() { + Backbone.Model.prototype.constructor.apply(this, arguments); + }, // ### defaults - define default values defaults: { label: null, @@ -445,11 +457,17 @@ my.Field = Backbone.Model.extend({ }); my.FieldList = Backbone.Collection.extend({ + constructor: function FieldList() { + Backbone.Collection.prototype.constructor.apply(this, arguments); + }, model: my.Field }); // ## Query my.Query = Backbone.Model.extend({ + constructor: function Query() { + Backbone.Model.prototype.constructor.apply(this, arguments); + }, defaults: function() { return { size: 100, @@ -534,6 +552,9 @@ my.Query = Backbone.Model.extend({ // ## A Facet (Result) my.Facet = Backbone.Model.extend({ + constructor: function Facet() { + Backbone.Model.prototype.constructor.apply(this, arguments); + }, defaults: function() { return { _type: 'terms', @@ -547,6 +568,9 @@ my.Facet = Backbone.Model.extend({ // ## A Collection/List of Facets my.FacetList = Backbone.Collection.extend({ + constructor: function FacetList() { + Backbone.Collection.prototype.constructor.apply(this, arguments); + }, model: my.Facet });