lib/Model.js
function Model(o) {

    var options = o || {};
    this._root = options._root || new ModelRoot(options);
    this._path = options.path || options._path || [];
    this._scheduler = options.scheduler || options._scheduler || new ImmediateScheduler();
    this._source = options.source || options._source;
    this._request = options.request || options._request || new RequestQueue(this, this._scheduler);
    this._ID = ID++;

    if (typeof options.maxSize === "number") {
        this._maxSize = options.maxSize;
    } else {
        this._maxSize = options._maxSize || Model.prototype._maxSize;
    }

    if (typeof options.maxRetries === "number") {
        this._maxRetries = options.maxRetries;
    } else {
        this._maxRetries = options._maxRetries || Model.prototype._maxRetries;
    }

    if (typeof options.collectRatio === "number") {
        this._collectRatio = options.collectRatio;
    } else {
        this._collectRatio = options._collectRatio || Model.prototype._collectRatio;
    }

    if (options.boxed || options.hasOwnProperty("_boxed")) {
        this._boxed = options.boxed || options._boxed;
    }

    if (options.materialized || options.hasOwnProperty("_materialized")) {
        this._materialized = options.materialized || options._materialized;
    }

    if (typeof options.treatErrorsAsValues === "boolean") {
        this._treatErrorsAsValues = options.treatErrorsAsValues;
    } else if (options.hasOwnProperty("_treatErrorsAsValues")) {
        this._treatErrorsAsValues = options._treatErrorsAsValues;
    }

    this._useServerPaths = options._useServerPaths || false;

    this._allowFromWhenceYouCame = options.allowFromWhenceYouCame ||
        options._allowFromWhenceYouCame || false;

    this._treatDataSourceErrorsAsJSONGraphErrors = options._treatDataSourceErrorsAsJSONGraphErrors || false;

    if (options.cache) {
        this.setCache(options.cache);
    }
}
function Model(o) {

    var options = o || {};
    this._root = options._root || new ModelRoot(options);
    this._path = options.path || options._path || [];
    this._scheduler = options.scheduler || options._scheduler || new ImmediateScheduler();
    this._source = options.source || options._source;
    this._request = options.request || options._request || new RequestQueue(this, this._scheduler);
    this._ID = ID++;

    if (typeof options.maxSize === "number") {
        this._maxSize = options.maxSize;
    } else {
        this._maxSize = options._maxSize || Model.prototype._maxSize;
    }

    if (typeof options.maxRetries === "number") {
        this._maxRetries = options.maxRetries;
    } else {
        this._maxRetries = options._maxRetries || Model.prototype._maxRetries;
    }

    if (typeof options.collectRatio === "number") {
        this._collectRatio = options.collectRatio;
    } else {
        this._collectRatio = options._collectRatio || Model.prototype._collectRatio;
    }

    if (options.boxed || options.hasOwnProperty("_boxed")) {
        this._boxed = options.boxed || options._boxed;
    }

    if (options.materialized || options.hasOwnProperty("_materialized")) {
        this._materialized = options.materialized || options._materialized;
    }

    if (typeof options.treatErrorsAsValues === "boolean") {
        this._treatErrorsAsValues = options.treatErrorsAsValues;
    } else if (options.hasOwnProperty("_treatErrorsAsValues")) {
        this._treatErrorsAsValues = options._treatErrorsAsValues;
    }

    this._useServerPaths = options._useServerPaths || false;

    this._allowFromWhenceYouCame = options.allowFromWhenceYouCame ||
        options._allowFromWhenceYouCame || false;

    this._treatDataSourceErrorsAsJSONGraphErrors = options._treatDataSourceErrorsAsJSONGraphErrors || false;

    if (options.cache) {
        this.setCache(options.cache);
    }
}
function Model ( o ) { var options = o || { } ; this . _root = options . _root || new ModelRoot ( options ) ; this . _path = options . path || options . _path || [ ] ; this . _scheduler = options . scheduler || options . _scheduler || new ImmediateScheduler ( ) ; this . _source = options . source || options . _source ; this . _request = options . request || options . _request || new RequestQueue ( this , this . _scheduler ) ; this . _ID = ID ++ ; if ( typeof options . maxSize === "number" ) { this . _maxSize = options . maxSize ; } else { this . _maxSize = options . _maxSize || Model . prototype . _maxSize ; } if ( typeof options . maxRetries === "number" ) { this . _maxRetries = options . maxRetries ; } else { this . _maxRetries = options . _maxRetries || Model . prototype . _maxRetries ; } if ( typeof options . collectRatio === "number" ) { this . _collectRatio = options . collectRatio ; } else { this . _collectRatio = options . _collectRatio || Model . prototype . _collectRatio ; } if ( options . boxed || options . hasOwnProperty ( "_boxed" ) ) { this . _boxed = options . boxed || options . _boxed ; } if ( options . materialized || options . hasOwnProperty ( "_materialized" ) ) { this . _materialized = options . materialized || options . _materialized ; } if ( typeof options . treatErrorsAsValues === "boolean" ) { this . _treatErrorsAsValues = options . treatErrorsAsValues ; } else if ( options . hasOwnProperty ( "_treatErrorsAsValues" ) ) { this . _treatErrorsAsValues = options . _treatErrorsAsValues ; } this . _useServerPaths = options . _useServerPaths || false ; this . _allowFromWhenceYouCame = options . allowFromWhenceYouCame || options . _allowFromWhenceYouCame || false ; this . _treatDataSourceErrorsAsJSONGraphErrors = options . _treatDataSourceErrorsAsJSONGraphErrors || false ; if ( options . cache ) { this . setCache ( options . cache ) ; } }
This function is invoked every time a value in the Model cache is about to be replaced with a new value. If the function returns true, the existing value is replaced with a new value and the version flag on all of the value's ancestors in the tree are incremented.
@callback Model~comparator
@param {Object} existingValue - the current value in the Model cache.
@param {Object} newValue - the value about to be set into the Model cache.
@returns {Boolean} the Boolean value indicating whether the new value and the existing value are equal.
 
A Model object is used to execute commands against a {@link JSONGraph} object. {@link Model}s can work with a local JSONGraph cache, or it can work with a remote {@link JSONGraph} object through a {@link DataSource}.
@constructor
@param {?Object} options - a set of options to customize behavior
@param {?DataSource} options.source - a data source to retrieve and manage the {@link JSONGraph}
@param {?JSONGraph} options.cache - initial state of the {@link JSONGraph}
@param {?number} options.maxSize - the maximum size of the cache. This value roughly correlates to item count (where itemCount = maxSize / 50). Each item by default is given a metadata `$size` of 50 (or its length when it's an array or string). You can get better control of falcor's memory usage by tweaking `$size`
@param {?number} options.maxRetries - the maximum number of times that the Model will attempt to retrieve the value from the server.
@param {?number} options.collectRatio - the ratio of the maximum size to collect when the maxSize is exceeded
@param {?Model~errorSelector} options.errorSelector - a function used to translate errors before they are returned
@param {?Model~onChange} options.onChange - a function called whenever the Model's cache is changed
@param {?Model~comparator} options.comparator - a function called whenever a value in the Model's cache is about to be replaced with a new value.
This function is invoked every time a value in the Model cache is about to be replaced with a new value . If the function returns true the existing value is replaced with a new value and the version flag on all of the value s ancestors in the tree are incremented .