View Full Version : Does anyone else see a need of before Init and after Init event?
deanna
12 Jul 2009, 7:15 PM
InitComponent is the place where I most need to override a component's parents method, and it is very prone to errors in calling the superclass version of the method. This happens when you decide to change the class the current class inherits from, such as Container to Panel - and you forget to update the method.
We have events for before and after render, it seems to make sense to have a before and after init event.
danh2000
12 Jul 2009, 9:29 PM
You say "it's prone to errors" although I'm not sure exactly what you mean.
Maybe I've misunderstood, but I personally don't see a need.
Consider this:
initComponent : {
//this section of the code could be considered beforeInit because I haven't called my superclass
//...
Ext.ux.mySubClass.superclass.initComponent.call(this);
//this section of the code could be considered afterInit
//..
}
If you are extending/overriding a parent you should always try not to use events anyway - if there are relevant template methods, these should always be used.
If I've misunderstood, maybe an example would help explain your case.
deanna
12 Jul 2009, 10:29 PM
I will give a conceptual example, since it is very late at night at the moment - if more is needed I can give a code based one in the morning.
I use config objects to specify my layouts. Unless the object is going to be reused I don't do a full extend as in your example, where I can safely say newclassname.superclass....apply()
Since I don't have a class name I have to resort to using the class name of the xtype directly. It will usually be something like Ext.Panel.prototype....apply() or Ext.Panel.superclass...apply() depending on whether it directly exists or not. This is a bit cumbersome and requires me to maintain that bit when I change the object xtype.
So for us that make extensive use of config blocks (as I also think the extjs designer package will if I understood the demo video), it would be nice to have events for the before and after init to avoid worrying about how to call the superclass version of the initComponent method. It would also be cleaner for everyone else too not to have to deal with that.
Animal
12 Jul 2009, 11:23 PM
If you do not extend, you will use
this.constructor.prototype.onXXXX.apply
deanna
12 Jul 2009, 11:37 PM
Thanks Animal, I had never seen that before. I guess that will take away a bit of the need for the events, although I still think they would be good for a consistency sake.
Animal
13 Jul 2009, 12:23 AM
Yes, events might be a good hook for those not happy to extend or override, or inject methods.
Meanwhile, look at the suggestions for adding functionality when a subclass is not required, the above technique is illustrated: http://extjs.com/learn/Tutorial:Creating_new_UI_controls#When_a_subclass_is_not_needed
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.