Resolve race conditions in Attachments.more(). Provides for smoother refreshes when searching and properly cleans out content components.
Props koopersmith fixes #22656 git-svn-id: https://develop.svn.wordpress.org/trunk@22956 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b80e435481
commit
303f2bd2ff
|
@ -490,9 +490,27 @@ window.wp = window.wp || {};
|
|||
},
|
||||
|
||||
more: function( options ) {
|
||||
if ( this.mirroring && this.mirroring.more )
|
||||
return this.mirroring.more( options );
|
||||
return $.Deferred().resolve().promise();
|
||||
var deferred = $.Deferred(),
|
||||
mirroring = this.mirroring,
|
||||
attachments = this;
|
||||
|
||||
if ( ! mirroring || ! mirroring.more )
|
||||
return deferred.resolveWith( this ).promise();
|
||||
|
||||
// If we're mirroring another collection, forward `more` to
|
||||
// the mirrored collection. Account for a race condition by
|
||||
// checking if we're still mirroring that collection when
|
||||
// the request resolves.
|
||||
mirroring.more( options ).done( function() {
|
||||
if ( this === attachments.mirroring )
|
||||
deferred.resolveWith( this );
|
||||
});
|
||||
|
||||
return deferred.promise();
|
||||
},
|
||||
|
||||
hasMore: function() {
|
||||
return this.mirroring ? this.mirroring.hasMore() : false;
|
||||
},
|
||||
|
||||
parse: function( resp, xhr ) {
|
||||
|
@ -583,9 +601,9 @@ window.wp = window.wp || {};
|
|||
options = options || {};
|
||||
Attachments.prototype.initialize.apply( this, arguments );
|
||||
|
||||
this.args = options.args;
|
||||
this.hasMore = true;
|
||||
this.created = new Date();
|
||||
this.args = options.args;
|
||||
this._hasMore = true;
|
||||
this.created = new Date();
|
||||
|
||||
this.filters.order = function( attachment ) {
|
||||
var orderby = this.props.get('orderby'),
|
||||
|
@ -627,21 +645,25 @@ window.wp = window.wp || {};
|
|||
this.observe( wp.Uploader.queue );
|
||||
},
|
||||
|
||||
hasMore: function() {
|
||||
return this._hasMore;
|
||||
},
|
||||
|
||||
more: function( options ) {
|
||||
var query = this;
|
||||
|
||||
if ( this._more && 'pending' === this._more.state() )
|
||||
return this._more;
|
||||
|
||||
if ( ! this.hasMore )
|
||||
return $.Deferred().resolve().promise();
|
||||
if ( ! this.hasMore() )
|
||||
return $.Deferred().resolveWith( this ).promise();
|
||||
|
||||
options = options || {};
|
||||
options.add = true;
|
||||
|
||||
return this._more = this.fetch( options ).done( function( resp ) {
|
||||
if ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page )
|
||||
query.hasMore = false;
|
||||
query._hasMore = false;
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -2821,7 +2821,7 @@
|
|||
if ( ! this.$el.is(':visible') )
|
||||
return;
|
||||
|
||||
if ( this.el.scrollHeight < this.el.scrollTop + ( this.el.clientHeight * this.options.refreshThreshold ) ) {
|
||||
if ( this.collection.hasMore() && this.el.scrollHeight < this.el.scrollTop + ( this.el.clientHeight * this.options.refreshThreshold ) ) {
|
||||
this.collection.more().done( this.scroll );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue