Skip to content
This repository
Browse code

Merge _collectionOptionsByCid & _modelOptionsByCid

  • Loading branch information...
commit 7a1dd6f48db146709c53fb919c6393c0e88250cf 1 parent 333b2ab
Ryan Eastridge authored
5 src/collection.js
@@ -40,7 +40,6 @@ createRegistryWrapper(Thorax.Collection, Thorax.Collections);
40 40 dataObject('collection', {
41 41 name: '_collectionEvents',
42 42 array: '_collections',
43   - hash: '_collectionOptionsByCid',
44 43 set: 'setCollection',
45 44 setCallback: afterSetCollection,
46 45 bind: 'bindCollection',
@@ -189,7 +188,7 @@ _.extend(Thorax.View.prototype, {
189 188 return element.length === 0 ? this.$el : element;
190 189 },
191 190 _onCollectionReset: function(collection) {
192   - if (collection === this.collection && this._collectionOptionsByCid[this.collection.cid].render) {
  191 + if (collection === this.collection && this._objectOptionsByCid[this.collection.cid].render) {
193 192 this.renderCollection();
194 193 }
195 194 },
@@ -233,7 +232,7 @@ _.extend(Thorax.View.prototype, {
233 232 Thorax.View.on({
234 233 collection: {
235 234 error: function(collection, message) {
236   - if (this._collectionOptionsByCid[collection.cid].errors) {
  235 + if (this._objectOptionsByCid[collection.cid].errors) {
237 236 this.trigger('error', message, collection);
238 237 }
239 238 }
10 src/data-object.js
@@ -61,21 +61,21 @@ function dataObject(type, spec) {
61 61 this[spec.array] = _.without(this[spec.array], dataObject);
62 62 dataObject.trigger('freeze');
63 63 this.stopListening(dataObject);
64   - delete this[spec.hash][dataObject.cid];
  64 + delete this._objectOptionsByCid[dataObject.cid];
65 65 return true;
66 66 }
67 67
68 68 function objectOptions(dataObject, options) {
69   - if (!this[spec.hash][dataObject.cid]) {
70   - this[spec.hash][dataObject.cid] = {
  69 + if (!this._objectOptionsByCid[dataObject.cid]) {
  70 + this._objectOptionsByCid[dataObject.cid] = {
71 71 render: true,
72 72 fetch: true,
73 73 success: false,
74 74 errors: true
75 75 };
76 76 }
77   - _.extend(this[spec.hash][dataObject.cid], options || {});
78   - return this[spec.hash][dataObject.cid];
  77 + _.extend(this._objectOptionsByCid[dataObject.cid], options || {});
  78 + return this._objectOptionsByCid[dataObject.cid];
79 79 }
80 80
81 81 function setObject(dataObject, options) {
2  src/form.js
@@ -8,7 +8,7 @@ extendOptions('_setModelOptions', function() {
8 8
9 9 extendViewMember('_onModelChange', function(model) {
10 10 // TODO : What can we do to remove this duplication?
11   - var modelOptions = model && this._modelOptionsByCid[model.cid];
  11 + var modelOptions = model && this._objectOptionsByCid[model.cid];
12 12 if (modelOptions && modelOptions.populate) {
13 13 this.populate(model.attributes, modelOptions.populate === true ? {} : modelOptions.populate);
14 14 }
5 src/model.js
@@ -26,7 +26,6 @@ createRegistryWrapper(Thorax.Model, Thorax.Models);
26 26 dataObject('model', {
27 27 name: '_modelEvents',
28 28 array: '_models',
29   - hash: '_modelOptionsByCid',
30 29 set: 'setModel',
31 30 bind: 'bindModel',
32 31 unbind: 'unbindModel',
@@ -38,7 +37,7 @@ dataObject('model', {
38 37
39 38 _.extend(Thorax.View.prototype, {
40 39 _onModelChange: function(model) {
41   - var modelOptions = model && this._modelOptionsByCid[model.cid];
  40 + var modelOptions = model && this._objectOptionsByCid[model.cid];
42 41 // !modelOptions will be true when setModel(false) is called
43 42 if (!modelOptions || (modelOptions && modelOptions.render)) {
44 43 this.render();
@@ -49,7 +48,7 @@ _.extend(Thorax.View.prototype, {
49 48 Thorax.View.on({
50 49 model: {
51 50 error: function(model, errors) {
52   - if (this._modelOptionsByCid[model.cid].errors) {
  51 + if (this._objectOptionsByCid[model.cid].errors) {
53 52 this.trigger('error', errors, model);
54 53 }
55 54 },
5 src/thorax.js
@@ -45,11 +45,12 @@ Thorax.View = Backbone.View.extend({
45 45 _configure: function(options) {
46 46 var self = this;
47 47
  48 + this._objectOptionsByCid = {};
  49 +
48 50 // Setup object event tracking
49 51 _.each(inheritVars, function(obj) {
50 52 self[obj.name] = [];
51 53 if (obj.array) { self[obj.array] = []; }
52   - if (obj.hash) { self[obj.hash] = {}; }
53 54 });
54 55
55 56 viewsIndexedByCid[this.cid] = this;
@@ -189,7 +190,7 @@ Thorax.View = Backbone.View.extend({
189 190 } else {
190 191 this.el.innerHTML = "";
191 192 var element;
192   - if (this.collection && this._collectionOptionsByCid[this.collection.cid] && this._renderCount) {
  193 + if (this.collection && this._objectOptionsByCid[this.collection.cid] && this._renderCount) {
193 194 // preserveCollectionElement calls the callback after it has a reference
194 195 // to the collection element, calls the callback, then re-appends the element
195 196 preserveCollectionElement.call(this, function() {

0 comments on commit 7a1dd6f

Please sign in to comment.
Something went wrong with that request. Please try again.