1. #1
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,701
    Vote Rating
    494
    LesJ has a brilliant future LesJ has a brilliant future LesJ has a brilliant future LesJ has a brilliant future LesJ has a brilliant future LesJ has a brilliant future LesJ has a brilliant future LesJ has a brilliant future LesJ has a brilliant future LesJ has a brilliant future LesJ has a brilliant future

      0  

    Default AbstractComponent - can I override the onDestroy method?

    Can a subclass override the AbstractComponent.onDestroy method? ... or is this method private and should I override the beforeDestroy method instead?

    Code:
    Ext.define('Ext.AbstractComponent', {
        ...
        /**
         * Invoked before the Component is destroyed.
         *
         * @method
         * @template
         * @protected
         */
        beforeDestroy : Ext.emptyFn,
        ...
        onDestroy : function() {
            ...
        },
        ....
    });

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    38,582
    Vote Rating
    1136
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default

    Any subclass can override it but it does a few things that you would need to clean up. I would just do a callParent
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,786
    Vote Rating
    379
    skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute

      0  

    Default

    Personally I wouldn't hesitate to override onDestroy if I needed to add destruction logic to a custom component. Choosing between onDestroy and beforeDestroy seems to be just a matter of timing.

    Methods with names that sound like events (e.g. onDestroy, afterRender) are to be thought of as 'internal events', intended to be overridden in subclasses. Of course you have to take care to call the overridden method at the appropriate time.

    There are some really old posts that you may find interesting. Here's one from Jack Slocum explaining his use of template methods in ExtJS 1. This principle remains in the current framework:

    http://www.sencha.com/forum/showthre...ll=1#post33312

    Later in the same thread he touches upon why he chose to name some methods after events:

    http://www.sencha.com/forum/showthre...ll=1#post33652

    This blog post from Nige White also touches upon this subject. Most of the post is about writing plugins but if you skim down you'll find he discusses some of the template methods in the framework:

    http://www.sencha.com/blog/advanced-...t-with-ext-js/

    He also explains some of the reasons why overriding methods is more appropriate than listening to events when writing an extension.

Thread Participants: 2