[backend.memory][s]: rename Store.data attribute to records to be more consistent (and more meaningful).

This commit is contained in:
Rufus Pollock
2013-01-03 21:50:47 +00:00
parent 4eb68fbf0f
commit e8ad368347
3 changed files with 33 additions and 30 deletions

View File

@@ -11,37 +11,39 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
// functionality like querying, faceting, updating (by ID) and deleting (by
// ID).
//
// @param data list of hashes for each record/row in the data ({key:
// @param records list of hashes for each record/row in the data ({key:
// value, key: value})
// @param fields (optional) list of field hashes (each hash defining a field
// as per recline.Model.Field). If fields not specified they will be taken
// from the data.
my.Store = function(data, fields) {
my.Store = function(records, fields) {
var self = this;
this.data = data;
this.records = records;
// backwards compatability (in v0.5 records was named data)
this.data = this.records;
if (fields) {
this.fields = fields;
} else {
if (data) {
this.fields = _.map(data[0], function(value, key) {
if (records) {
this.fields = _.map(records[0], function(value, key) {
return {id: key, type: 'string'};
});
}
}
this.update = function(doc) {
_.each(self.data, function(internalDoc, idx) {
_.each(self.records, function(internalDoc, idx) {
if(doc.id === internalDoc.id) {
self.data[idx] = doc;
self.records[idx] = doc;
}
});
};
this.remove = function(doc) {
var newdocs = _.reject(self.data, function(internalDoc) {
var newdocs = _.reject(self.records, function(internalDoc) {
return (doc.id === internalDoc.id);
});
this.data = newdocs;
this.records = newdocs;
};
this.save = function(changes, dataset) {
@@ -60,9 +62,9 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
this.query = function(queryObj) {
var dfd = $.Deferred();
var numRows = queryObj.size || this.data.length;
var numRows = queryObj.size || this.records.length;
var start = queryObj.from || 0;
var results = this.data;
var results = this.records;
results = this._applyFilters(results, queryObj);
results = this._applyFreeTextQuery(results, queryObj);
@@ -229,9 +231,9 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
this.transform = function(editFunc) {
var dfd = $.Deferred();
// TODO: should we clone before mapping? Do not see the point atm.
self.data = _.map(self.data, editFunc);
self.records = _.map(self.records, editFunc);
// now deal with deletes (i.e. nulls)
self.data = _.filter(self.data, function(record) {
self.records = _.filter(self.records, function(record) {
return record != null;
});
dfd.resolve();