further refactoring

This commit is contained in:
Max Ogden
2011-11-03 19:13:17 +00:00
parent 9674e10119
commit 2ec378997e
2 changed files with 29 additions and 25 deletions

View File

@@ -2,26 +2,27 @@ this.recline = this.recline || {};
// A Dataset model. // A Dataset model.
recline.Dataset = Backbone.Model.extend({ recline.Dataset = Backbone.Model.extend({
initialize: function(data, rawTabularData) { initialize: function(data, rawDocumentSet) {
this.tabularData = new recline.TabularData(rawTabularData); this.documentSet = new recline.DocumentSet(rawDocumentSet);
} }
// get TabularData object associated with this Dataset
//
// async (as may involve getting data from the server) implementing standard promise API
, getTabularData: function() {
var dfd = $.Deferred();
dfd.resolve(this.tabularData);
return dfd.promise();
}
}); });
// TabularData model recline.Document = Backbone.Model.extend({});
recline.TabularData = Backbone.Model.extend({
recline.DocumentList = Backbone.Collection.extend({
// webStore: new WebStore(this.url),
model: recline.Document
})
recline.DocumentSet = Backbone.Model.extend({
fetch: function(options) {
options.success(this);
},
getLength: function() { getLength: function() {
return this.get('rows').length; return this.get('rows').length;
} },
, getRows: function(numRows, start) { getRows: function(numRows, start) {
if (start === undefined) { if (start === undefined) {
start = 0; start = 0;
} }
@@ -33,4 +34,5 @@ recline.TabularData = Backbone.Model.extend({
dfd.resolve(results); dfd.resolve(results);
return dfd.promise(); return dfd.promise();
} }
}); });

View File

@@ -23,16 +23,18 @@ test('new Dataset', function () {
equal(dataset.get('name'), metadata.name); equal(dataset.get('name'), metadata.name);
expect(6); expect(6);
setTimeout(2); setTimeout(2);
dataset.getTabularData().then(function(tabularData) { dataset.documentSet.fetch({
equal(tabularData.get('headers'), indata.headers); success: function(documentSet) {
equal(tabularData.getLength(), 6); equal(documentSet.get('headers'), indata.headers);
tabularData.getRows(4, 2).then(function(rows) { equal(documentSet.getLength(), 6);
equal(rows[0], indata.rows[2]); documentSet.getRows(4, 2).then(function(rows) {
}); equal(rows[0], indata.rows[2]);
tabularData.getRows().then(function(rows) { });
equal(rows.length, Math.min(10, indata.rows.length)); documentSet.getRows().then(function(rows) {
equal(rows[0], indata.rows[0]); equal(rows.length, Math.min(10, indata.rows.length));
}); equal(rows[0], indata.rows[0]);
});
}
}); });
}); });