[#291,bugfix][s]: memory backend transform function now works even when records do not have id - fixes #291.

* Also simplified (and made more efficient) by removing dependency on (not very useful) recline.Data.Transform.mapDocs function
* As documented in #291 issue was that an id was required in the docs
This commit is contained in:
Rufus Pollock
2012-12-22 19:51:03 +00:00
parent 7f35cffe3c
commit 3610d95e74
2 changed files with 33 additions and 5 deletions

View File

@@ -227,12 +227,15 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
};
this.transform = function(editFunc) {
var toUpdate = recline.Data.Transform.mapDocs(this.data, editFunc);
// TODO: very inefficient -- could probably just walk the documents and updates in tandem and update
_.each(toUpdate.updates, function(record, idx) {
self.data[idx] = record;
var dfd = $.Deferred();
// TODO: should we clone before mapping? Do not see the point atm.
self.data = _.map(self.data, editFunc);
// now deal with deletes (i.e. nulls)
self.data = _.filter(self.data, function(record) {
return record != null;
});
return this.save(toUpdate);
dfd.resolve();
return dfd.promise();
};
};