Make WordPress Core

Changeset 24609


Ignore:
Timestamp:
07/09/2013 08:50:32 AM (13 years ago)
Author:
koopersmith
Message:

Revisions: Move data management into the frame state. See #24425.

This helps to solidify the separation between data and UI. We track the diffId internally now, as the property itself was never referenced, and was always derived from the 'from' and 'to' models. This also sets us up for better request debouncing and diff management.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/revisions.js

    r24608 r24609  
    210210                // the changed attributes in `set`, and then fires the `change` events.
    211211                updateDiff: function() {
    212                         var from = this.get('from');
    213                         this.set( 'diffId', (from ? from.id : '0' ) + ':' + this.get('to').id );
     212                        var from, to, diffId;
     213
     214                        from = this.get('from');
     215                        to = this.get('to');
     216                        diffId = ( from ? from.id : 0 ) + ':' + to.id;
     217
     218                        // Check if we're actually changing the diff id.
     219                        if ( this._diffId === diffId )
     220                                return;
     221
     222                        this._diffId = diffId;
     223                        this.trigger( 'update:revisions', from, to );
     224
     225                        this.diffs.ensure( diffId, this ).done( function( diff ) {
     226                                // Check if the current diff changed while the request was in flight.
     227                                if ( this._diffId !== diff.id )
     228                                        return;
     229
     230                                this.trigger( 'update:diff', diff );
     231                        });
    214232                }
    215233        });
     
    232250                        });
    233251
    234                         this.listenTo( this.model, 'change:diffId', this.updateDiff );
     252                        this.listenTo( this.model, 'update:diff', this.renderDiff );
    235253                        this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
    236254
     
    265283                },
    266284
    267                 updateDiff: function() {
    268                         this.model.diffs.ensure( this.model.get('diffId'), this ).done( function( diff ) {
    269                                 if ( this.model.get('diffId') !== diff.id )
    270                                         return;
    271 
    272                                 this.views.set( '.revisions-diff-frame', new revisions.view.Diff({
    273                                         model: diff
    274                                 }) );
    275 
    276                                 this.model.trigger('renderDiff');
    277                         });
     285                renderDiff: function( diff ) {
     286                        this.views.set( '.revisions-diff-frame', new revisions.view.Diff({
     287                                model: diff
     288                        }) );
    278289                },
    279290
     
    365376
    366377                initialize: function() {
    367                         this.listenTo( this.model, 'change:diffId', this.updateMeta );
     378                        this.listenTo( this.model, 'update:revisions', this.updateMeta );
    368379                },
    369380
     
    373384                },
    374385
    375                 updateMeta: function() {
     386                updateMeta: function( from, to ) {
    376387                        this.$el.html( this.template( this.model.toJSON() ) );
    377388
    378                         $('#restore-revision').prop( 'disabled', this.model.get('to').attributes.current );
     389                        $('#restore-revision').prop( 'disabled', to.attributes.current );
    379390                }
    380391        });
     
    482493
    483494                ready: function() {
    484                         this.listenTo( this.model, 'change:diffId', this.disabledButtonCheck );
     495                        this.listenTo( this.model, 'update:revisions', this.disabledButtonCheck );
    485496                },
    486497
     
    583594                        }, this );
    584595
    585                         // Listen for changes in the diffId
    586                         this.listenTo( this.model, 'change:diffId', this.diffIdChanged );
     596                        // Listen for changes to the revisions
     597                        this.listenTo( this.model, 'update:revisions', this.updateRevisions );
    587598                },
    588599
     
    673684                },
    674685
    675                 diffIdChanged: function() {
    676                         // Reset the view settings when diffId is changed
     686                updateRevisions: function( from, to ) {
     687                        // Update the view settings when the revisions have changed.
    677688                        if ( this.model.get('compareTwoMode') ) {
    678689                                this.settings.set({ 'values': [
    679                                         this.model.revisions.indexOf( this.model.get('from') ),
    680                                         this.model.revisions.indexOf( this.model.get('to') )
     690                                        this.model.revisions.indexOf( from ),
     691                                        this.model.revisions.indexOf( to )
    681692                                ] });
    682693                        } else {
    683                                 this.settings.set({ 'value': this.model.revisions.indexOf( this.model.get('to') ) });
     694                                this.settings.set({ 'value': this.model.revisions.indexOf( to ) });
    684695                        }
    685696                },
Note: See TracChangeset for help on using the changeset viewer.