-
16 Feb 2012 9:21 AM #1
AbstractComponent - can I override the onDestroy method?
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() { ... }, .... });
-
16 Feb 2012 9:53 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
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 Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
16 Feb 2012 3:57 PM #3
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.


Reply With Quote