ampersand-filtered-subcollection.js
function () {
        // make a copy of the array for comparisons
        var existingModels = slice.call(this.models);
        var rootModels = slice.call(this.collection.models);
        var newIndexes = {};
        var newModels, toAdd, toRemove;

        this._resetIndexes(newIndexes);

        // reduce base model set by applying filters
        if (this._filters.length) {
            newModels = reduce(this._filters, function (startingArray, filterFunc) {
                return startingArray.filter(filterFunc);
            }, rootModels);
        } else {
            newModels = slice.call(rootModels);
        }

        // sort it
        if (this.comparator) newModels = this._sortModels(newModels, this.comparator);

        newModels.forEach(function (model) {
            this._addIndex(newIndexes, model);
        }, this);

        // Cache a reference to the full filtered set to allow this._filtered.length. Ref: #6
        if (rootModels.length) {
            this._filtered = newModels;
            this._indexes = newIndexes;
        } else {
            this._filtered = [];
            this._resetIndexes(this._indexes);
        }

        // now we've got our new models time to compare
        toAdd = difference(newModels, existingModels);
        toRemove = difference(existingModels, newModels);

        // save 'em
        this.models = newModels;

        forEach(toRemove, bind(function (model) {
            this.trigger('remove', model, this);
        }, this));

        forEach(toAdd, bind(function (model) {
            this.trigger('add', model, this);
        }, this));

        // unless we have the same models in same order trigger `sort`
        if (!isEqual(existingModels, newModels) && this.comparator) {
            this.trigger('sort', this);
        }
    }
function () {
        // make a copy of the array for comparisons
        var existingModels = slice.call(this.models);
        var rootModels = slice.call(this.collection.models);
        var newIndexes = {};
        var newModels, toAdd, toRemove;

        this._resetIndexes(newIndexes);

        // reduce base model set by applying filters
        if (this._filters.length) {
            newModels = reduce(this._filters, function (startingArray, filterFunc) {
                return startingArray.filter(filterFunc);
            }, rootModels);
        } else {
            newModels = slice.call(rootModels);
        }

        // sort it
        if (this.comparator) newModels = this._sortModels(newModels, this.comparator);

        newModels.forEach(function (model) {
            this._addIndex(newIndexes, model);
        }, this);

        // Cache a reference to the full filtered set to allow this._filtered.length. Ref: #6
        if (rootModels.length) {
            this._filtered = newModels;
            this._indexes = newIndexes;
        } else {
            this._filtered = [];
            this._resetIndexes(this._indexes);
        }

        // now we've got our new models time to compare
        toAdd = difference(newModels, existingModels);
        toRemove = difference(existingModels, newModels);

        // save 'em
        this.models = newModels;

        forEach(toRemove, bind(function (model) {
            this.trigger('remove', model, this);
        }, this));

        forEach(toAdd, bind(function (model) {
            this.trigger('add', model, this);
        }, this));

        // unless we have the same models in same order trigger `sort`
        if (!isEqual(existingModels, newModels) && this.comparator) {
            this.trigger('sort', this);
        }
    }
function ( ) { // make a copy of the array for comparisons var existingModels = slice . call ( this . models ) ; var rootModels = slice . call ( this . collection . models ) ; var newIndexes = { } ; var newModels , toAdd , toRemove ; this . _resetIndexes ( newIndexes ) ; // reduce base model set by applying filters if ( this . _filters . length ) { newModels = reduce ( this . _filters , function ( startingArray , filterFunc ) { return startingArray . filter ( filterFunc ) ; } , rootModels ) ; } else { newModels = slice . call ( rootModels ) ; } // sort it if ( this . comparator ) newModels = this . _sortModels ( newModels , this . comparator ) ; newModels . forEach ( function ( model ) { this . _addIndex ( newIndexes , model ) ; } , this ) ; // Cache a reference to the full filtered set to allow this._filtered.length. Ref: #6 if ( rootModels . length ) { this . _filtered = newModels ; this . _indexes = newIndexes ; } else { this . _filtered = [ ] ; this . _resetIndexes ( this . _indexes ) ; } // now we've got our new models time to compare toAdd = difference ( newModels , existingModels ) ; toRemove = difference ( existingModels , newModels ) ; // save 'em this . models = newModels ; forEach ( toRemove , bind ( function ( model ) { this . trigger ( 'remove' , model , this ) ; } , this ) ) ; forEach ( toAdd , bind ( function ( model ) { this . trigger ( 'add' , model , this ) ; } , this ) ) ; // unless we have the same models in same order trigger `sort` if ( ! isEqual ( existingModels , newModels ) && this . comparator ) { this . trigger ( 'sort' , this ) ; } }
Re-run the filters on all our parent's models
Re - run the filters on all our parent s models