Make WordPress Core

Changeset 24361


Ignore:
Timestamp:
05/25/2013 09:38:12 PM (13 years ago)
Author:
koopersmith
Message:

Update the subview controller for the patterns found in Backbone 1.0.

Fixes #24424.

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

Legend:

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

    r24360 r24361  
    848848    //
    849849    // The base view class.
    850     media.View = wp.View;
     850    //
     851    // Undelegating events, removing events from the model, and
     852    // removing events from the controller mirror the code for
     853    // `Backbone.View.dispose` in Backbone 0.9.8 development.
     854    //
     855    // This behavior has since been removed, and should not be used
     856    // outside of the media manager.
     857    media.View = wp.View.extend({
     858        constructor: function( options ) {
     859            if ( options && options.controller )
     860                this.controller = options.controller;
     861
     862            wp.View.apply( this, arguments );
     863        },
     864
     865        dispose: function() {
     866            // Undelegating events, removing events from the model, and
     867            // removing events from the controller mirror the code for
     868            // `Backbone.View.dispose` in Backbone 0.9.8 development.
     869            this.undelegateEvents();
     870
     871            if ( this.model && this.model.off )
     872                this.model.off( null, null, this );
     873
     874            if ( this.collection && this.collection.off )
     875                this.collection.off( null, null, this );
     876
     877            // Unbind controller events.
     878            if ( this.controller && this.controller.off )
     879                this.controller.off( null, null, this );
     880
     881            return this;
     882        },
     883
     884        remove: function() {
     885            this.dispose();
     886            return wp.View.prototype.remove.apply( this, arguments );
     887        }
     888    });
    851889
    852890    /**
  • trunk/wp-includes/js/wp-backbone.js

    r24360 r24361  
    127127                            view.$el.detach();
    128128                        else
    129                             view.dispose();
     129                            view.remove();
    130130                    });
    131131
     
    183183        // Stops tracking `views` registered to a `selector`. If no `views` are
    184184        // set, then all of the `selector`'s subviews will be unregistered and
    185         // disposed.
    186         //
    187         // Accepts an `options` object. If `options.silent` is set, `dispose`
     185        // removed.
     186        //
     187        // Accepts an `options` object. If `options.silent` is set, `remove`
    188188        // will *not* be triggered on the unregistered views.
    189189        unset: function( selector, views, options ) {
     
    204204
    205205            if ( ! options || ! options.silent )
    206                 _.invoke( views, 'dispose' );
     206                _.invoke( views, 'remove' );
    207207
    208208            return this;
     
    236236        },
    237237
    238         // ### Dispose all subviews
    239         //
    240         // Triggers the `dispose()` method on all subviews. Detaches the master
     238        // ### Remove all subviews
     239        //
     240        // Triggers the `remove()` method on all subviews. Detaches the master
    241241        // view from its parent. Resets the internals of the views manager.
    242242        //
    243243        // Accepts an `options` object. If `options.silent` is set, `unset`
    244244        // will *not* be triggered on the master view's parent.
    245         dispose: function( options ) {
     245        remove: function( options ) {
    246246            if ( ! options || ! options.silent ) {
    247247                if ( this.parent && this.parent.views )
     
    251251            }
    252252
    253             _.invoke( this.all(), 'dispose' );
     253            _.invoke( this.all(), 'remove' );
    254254            this._views = [];
    255255            return this;
     
    362362        Subviews: wp.Subviews,
    363363
    364         constructor: function( options ) {
     364        constructor: function() {
    365365            this.views = new this.Subviews( this, this.views );
    366366            this.on( 'ready', this.ready, this );
    367367
    368             if ( options && options.controller )
    369                 this.controller = options.controller;
    370 
    371368            Backbone.View.apply( this, arguments );
    372369        },
    373370
    374         dispose: function() {
    375             // Undelegating events, removing events from the model, and
    376             // removing events from the controller mirror the code for
    377             // `Backbone.View.dispose` in Backbone master.
    378             this.undelegateEvents();
    379 
    380             if ( this.model && this.model.off )
    381                 this.model.off( null, null, this );
    382 
    383             if ( this.collection && this.collection.off )
    384                 this.collection.off( null, null, this );
    385 
    386             // Unbind controller events.
    387             if ( this.controller && this.controller.off )
    388                 this.controller.off( null, null, this );
    389 
    390             // Recursively dispose child views.
     371        remove: function() {
     372            var result = Backbone.View.prototype.remove.apply( this, arguments );
     373
     374            // Recursively remove child views.
    391375            if ( this.views )
    392                 this.views.dispose();
    393 
    394             return this;
    395         },
    396 
    397         remove: function() {
    398             this.dispose();
    399             return Backbone.View.prototype.remove.apply( this, arguments );
     376                this.views.remove();
     377
     378            return result;
    400379        },
    401380
Note: See TracChangeset for help on using the changeset viewer.