[model/dataset][m]: introduce Model module containing basic Dataset and TabularData objects (plus tests).

* NB: current Dataset is basic one running off local data.
This commit is contained in:
rgrp
2011-11-03 09:00:42 +00:00
parent abe387a65e
commit c144dda731
3 changed files with 88 additions and 1 deletions

43
src/dataset.js Normal file
View File

@@ -0,0 +1,43 @@
this.RECLINE = this.RECLINE || {};
RECLINE.Model = function ($, _, Backbone) {
var my = {};
// A Dataset model.
my.Dataset = Backbone.Model.extend({
initialize: function(data, rawTabularData) {
this.tabularData = new my.TabularData(rawTabularData);
}
// 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
my.TabularData = Backbone.Model.extend({
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();
}
});
return my;
}(this.jQuery, this._, this.Backbone);