Don't call `updateDiff()` in the Revisions FrameState model.

* Stuff needs to hook in, so firing it early results in a half-rendered screen.
* `updateDiff()` now returns a promise.
* Now, in the frame view's `render()`, it calls `updateDiff()`, relying on its promise.

See #24425.

git-svn-id: https://develop.svn.wordpress.org/trunk@24622 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2013-07-10 03:20:58 +00:00
parent 1b035dc715
commit e62170f6e2
1 changed files with 13 additions and 10 deletions

View File

@ -259,7 +259,6 @@ window.wp = window.wp || {};
this.listenTo( this, 'change:to', this.changeRevisionHandler ); this.listenTo( this, 'change:to', this.changeRevisionHandler );
this.listenTo( this, 'update:revisions', this.loadSurrounding ); this.listenTo( this, 'update:revisions', this.loadSurrounding );
this.listenTo( this, 'change:compareTwoMode', this.changedMode ); this.listenTo( this, 'change:compareTwoMode', this.changedMode );
this.updateDiff({ immediate: true });
}, },
changedMode: function() { changedMode: function() {
@ -300,7 +299,7 @@ window.wp = window.wp || {};
// Check if we're actually changing the diff id. // Check if we're actually changing the diff id.
if ( this._diffId === diffId ) if ( this._diffId === diffId )
return; return $.Deferred().fail().promise();
this._diffId = diffId; this._diffId = diffId;
this.trigger( 'update:revisions', from, to ); this.trigger( 'update:revisions', from, to );
@ -309,13 +308,15 @@ window.wp = window.wp || {};
diff = this.diffs.get( diffId ); diff = this.diffs.get( diffId );
if ( diff ) { if ( diff ) {
this.trigger( 'update:diff', diff ); this.trigger( 'update:diff', diff );
return $.Deferred().resolve().promise();
// Otherwise, fetch the diff. // Otherwise, fetch the diff.
} else { } else {
if ( options.immediate ) if ( options.immediate ) {
this._ensureDiff(); return this._ensureDiff();
else } else {
this._debouncedEnsureDiff(); this._debouncedEnsureDiff();
return $.Deferred().fail().promise();
}
} }
}, },
@ -326,7 +327,7 @@ window.wp = window.wp || {};
}, },
_ensureDiff: function() { _ensureDiff: function() {
this.diffs.ensure( this._diffId, this ).done( function( diff ) { return this.diffs.ensure( this._diffId, this ).done( function( diff ) {
// Make sure the current diff didn't change while the request was in flight. // Make sure the current diff didn't change while the request was in flight.
if ( this._diffId === diff.id ) if ( this._diffId === diff.id )
this.trigger( 'update:diff', diff ); this.trigger( 'update:diff', diff );
@ -361,10 +362,12 @@ window.wp = window.wp || {};
}, },
render: function() { render: function() {
wp.Backbone.View.prototype.render.apply( this, arguments ); this.model.updateDiff({ immediate: true }).done( _.bind( function() {
wp.Backbone.View.prototype.render.apply( this, arguments );
$('#wpbody-content .wrap').append( this.el ); $('#wpbody-content .wrap').append( this.el );
this.views.ready(); this.views.ready();
}, this ) );
return this; return this;
}, },