falcor
Version:
A JavaScript library for efficient data fetching.
40 lines (31 loc) • 1.13 kB
JavaScript
var isFunction = require("./support/isFunction");
var hasOwn = require("./support/hasOwn");
function ModelRoot(o) {
var options = o || {};
this.syncRefCount = 0;
this.expired = options.expired || [];
this.unsafeMode = options.unsafeMode || false;
this.cache = {};
if (isFunction(options.comparator)) {
this.comparator = options.comparator;
}
if (isFunction(options.errorSelector)) {
this.errorSelector = options.errorSelector;
}
if (isFunction(options.onChange)) {
this.onChange = options.onChange;
}
}
ModelRoot.prototype.errorSelector = function errorSelector(x, y) {
return y;
};
ModelRoot.prototype.comparator = function comparator(cacheNode, messageNode) {
if (hasOwn(cacheNode, "value") && hasOwn(messageNode, "value")) {
// They are the same only if the following fields are the same.
return cacheNode.value === messageNode.value &&
cacheNode.$type === messageNode.$type &&
cacheNode.$expires === messageNode.$expires;
}
return cacheNode === messageNode;
};
module.exports = ModelRoot;