Make WordPress Core

Changeset 22956


Ignore:
Timestamp:
11/30/2012 04:41:38 PM (11 years ago)
Author:
ryan
Message:

Resolve race conditions in Attachments.more(). Provides for smoother refreshes when searching and properly cleans out content components.

Props koopersmith
fixes #22656

Location:
trunk/wp-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/media-models.js

    r22952 r22956  
    491491
    492492        more: function( options ) {
    493             if ( this.mirroring && this.mirroring.more )
    494                 return this.mirroring.more( options );
    495             return $.Deferred().resolve().promise();
     493            var deferred = $.Deferred(),
     494                mirroring = this.mirroring,
     495                attachments = this;
     496
     497            if ( ! mirroring || ! mirroring.more )
     498                return deferred.resolveWith( this ).promise();
     499
     500            // If we're mirroring another collection, forward `more` to
     501            // the mirrored collection. Account for a race condition by
     502            // checking if we're still mirroring that collection when
     503            // the request resolves.
     504            mirroring.more( options ).done( function() {
     505                if ( this === attachments.mirroring )
     506                    deferred.resolveWith( this );
     507            });
     508
     509            return deferred.promise();
     510        },
     511
     512        hasMore: function() {
     513            return this.mirroring ? this.mirroring.hasMore() : false;
    496514        },
    497515
     
    584602            Attachments.prototype.initialize.apply( this, arguments );
    585603
    586             this.args    = options.args;
    587             this.hasMore = true;
    588             this.created = new Date();
     604            this.args     = options.args;
     605            this._hasMore = true;
     606            this.created  = new Date();
    589607
    590608            this.filters.order = function( attachment ) {
     
    628646        },
    629647
     648        hasMore: function() {
     649            return this._hasMore;
     650        },
     651
    630652        more: function( options ) {
    631653            var query = this;
     
    634656                return this._more;
    635657
    636             if ( ! this.hasMore )
    637                 return $.Deferred().resolve().promise();
     658            if ( ! this.hasMore() )
     659                return $.Deferred().resolveWith( this ).promise();
    638660
    639661            options = options || {};
     
    642664            return this._more = this.fetch( options ).done( function( resp ) {
    643665                if ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page )
    644                     query.hasMore = false;
     666                    query._hasMore = false;
    645667            });
    646668        },
  • trunk/wp-includes/js/media-views.js

    r22952 r22956  
    28222822                return;
    28232823
    2824             if ( this.el.scrollHeight < this.el.scrollTop + ( this.el.clientHeight * this.options.refreshThreshold ) ) {
     2824            if ( this.collection.hasMore() && this.el.scrollHeight < this.el.scrollTop + ( this.el.clientHeight * this.options.refreshThreshold ) ) {
    28252825                this.collection.more().done( this.scroll );
    28262826            }
Note: See TracChangeset for help on using the changeset viewer.