[model,refactor][m]: (refs #6, refs #10) get rid of DocumentSet merging its functionality into Dataset.

* In addition fully remove remaining references in models (in getRows and getLength functions) to form of backend (this should have been in previous commit).
This commit is contained in:
rgrp
2011-11-05 20:20:31 +00:00
parent 21d9a1c2dc
commit 3a48044a76
4 changed files with 39 additions and 37 deletions

View File

@@ -2,7 +2,15 @@ this.recline = this.recline || {};
// A Dataset model.
recline.Dataset = Backbone.Model.extend({
__type__: 'Dataset'
__type__: 'Dataset',
getLength: function() {
return this.rowCount;
},
// this does not fit very well with Backbone setup. Backbone really expects you to know the ids of objects your are fetching (which you do in classic RESTful ajax-y world). But this paradigm does not fill well with data set up we have here.
// This also illustrates the limitations of separating the Dataset and the Backend
getRows: function(numRows, start) {
return this.backend.getRows(this.id, numRows, start);
}
});
recline.Document = Backbone.Model.extend({});
@@ -12,25 +20,6 @@ recline.DocumentList = Backbone.Collection.extend({
model: recline.Document
})
recline.DocumentSet = Backbone.Model.extend({
__type__: 'DocumentSet',
getLength: function() {
return this.get('rows').length;
},
getRows: function(numRows, start) {
if (start === undefined) {
start = 0;
}
if (numRows === undefined) {
numRows = 10;
}
var dfd = $.Deferred();
var results = this.get('rows').slice(start, start+numRows);
dfd.resolve(results);
return dfd.promise();
}
});
// Backend which just caches in memory
//
// Does not need to be a backbone model but provides some conveience
@@ -59,15 +48,29 @@ recline.BackendMemory = Backbone.Model.extend({
var dataset = this;
var rawDataset = this.backend._datasetCache[model.id];
dataset.set(rawDataset.metadata);
dataset.documentSet = new recline.DocumentSet(rawDataset.data);
dataset.documentSet.dataset = dataset;
// here we munge it all onto Dataset
dataset.set({
headers: rawDataset.data.headers
});
dataset.rowCount = rawDataset.data.rows.length;
dfd.resolve(dataset);
} else if (this.__type__ == 'DocumentSet') {
dfd.resolve(this);
}
return dfd.promise();
}
}
},
getRows: function(datasetId, numRows, start) {
if (start === undefined) {
start = 0;
}
if (numRows === undefined) {
numRows = 10;
}
var dfd = $.Deferred();
rows = this._datasetCache[datasetId].data.rows;
var results = rows.slice(start, start+numRows);
dfd.resolve(results);
return dfd.promise();
}
});
recline.setBackend = function(backend) {