From e62170f6e26e56eccc7ef5a91422e5e701e950be Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Wed, 10 Jul 2013 03:20:58 +0000 Subject: [PATCH] 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 --- wp-admin/js/revisions.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/wp-admin/js/revisions.js b/wp-admin/js/revisions.js index 7d42418ba5..987ec56a75 100644 --- a/wp-admin/js/revisions.js +++ b/wp-admin/js/revisions.js @@ -259,7 +259,6 @@ window.wp = window.wp || {}; this.listenTo( this, 'change:to', this.changeRevisionHandler ); this.listenTo( this, 'update:revisions', this.loadSurrounding ); this.listenTo( this, 'change:compareTwoMode', this.changedMode ); - this.updateDiff({ immediate: true }); }, changedMode: function() { @@ -300,7 +299,7 @@ window.wp = window.wp || {}; // Check if we're actually changing the diff id. if ( this._diffId === diffId ) - return; + return $.Deferred().fail().promise(); this._diffId = diffId; this.trigger( 'update:revisions', from, to ); @@ -309,13 +308,15 @@ window.wp = window.wp || {}; diff = this.diffs.get( diffId ); if ( diff ) { this.trigger( 'update:diff', diff ); - + return $.Deferred().resolve().promise(); // Otherwise, fetch the diff. } else { - if ( options.immediate ) - this._ensureDiff(); - else + if ( options.immediate ) { + return this._ensureDiff(); + } else { this._debouncedEnsureDiff(); + return $.Deferred().fail().promise(); + } } }, @@ -326,7 +327,7 @@ window.wp = window.wp || {}; }, _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. if ( this._diffId === diff.id ) this.trigger( 'update:diff', diff ); @@ -361,10 +362,12 @@ window.wp = window.wp || {}; }, 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 ); - this.views.ready(); + $('#wpbody-content .wrap').append( this.el ); + this.views.ready(); + }, this ) ); return this; },