W.R.T. the transform functionality:
I am using a caching factory so that my model instance is only represented once in memory.
changed: function (id, fields) {
var strId = LocalCollection._idStringify(id);
var doc = docs[strId];
var oldDoc = EJSON.clone(doc);
// writes through to the doc set
LocalCollection._applyChanges(doc, fields);
=> suppressed || callbacks.changed && callbacks.changed(transform(doc), transform(oldDoc));
One improvement I can suggest is to reverse the order in which the transforms are done:
if(!suppressed && callbacks.changed) {
oldDoc = transform(oldDoc);
callbacks.changed(transform(doc), oldDoc);
}
or just don't call the transform on the oldDoc.
What do people think? Is this a reasonable request or am I causing myself grief by caching the model/transform?