mongoose-diff-tracking
Version:
Manage Mongo Collection diff History and versions
29 lines (24 loc) • 810 B
JavaScript
var Context = require('./context').Context;
var dateReviver = require('../date-reviver');
var DiffContext = function DiffContext(left, right) {
this.left = left;
this.right = right;
this.pipe = 'diff';
};
DiffContext.prototype = new Context();
DiffContext.prototype.setResult = function(result) {
if (this.options.cloneDiffValues) {
var clone = typeof this.options.cloneDiffValues === 'function' ?
this.options.cloneDiffValues : function(value) {
return JSON.parse(JSON.stringify(value), dateReviver);
};
if (typeof result[0] === 'object') {
result[0] = clone(result[0]);
}
if (typeof result[1] === 'object') {
result[1] = clone(result[1]);
}
}
return Context.prototype.setResult.apply(this, arguments);
};
exports.DiffContext = DiffContext;