PDA

View Full Version : 0.96 defer problem!?



willi
5 Oct 2010, 7:42 AM
Hi,

since 0.96 the following code with 'defer' isn't working any more:


setThisText.defer(1000, this, ['btnA', cont]);The function called sets the button's text:


function setThisText(thisID, thisTxt) {
Ext.getCmp(thisID).setText(thisTxt);
}With 0.95 this worked. What is the problem now?

Btw, I read that 'Ext.getCmp(id)' isn't a good approach. What is the best way to access your components then?

Thanks

evant
5 Oct 2010, 2:00 PM
We decided to stop augmenting the prototype with custom functions so that Ext will always play nicely with other libraries. One of the unfortunate trade-offs is now you need to use:



Ext.defer(setThisText, 1000, ......);

willi
5 Oct 2010, 11:32 PM
Thanks, it works again!

gabrielstuff
8 Oct 2010, 9:53 AM
What about Ext.getCmp ? How bad is it and why ?

willi
11 Oct 2010, 1:38 AM
It's been in the thred
panel content under toolbar where jgarcia wrote:
... i highly suggest not developing your apps depending on Ext.getCmp();.
And in
0.96 itemtap problem mitchellsimoens says:
Ext.getCmp should be used for development only.

Can anybody explain this issue a little bit?

evant
11 Oct 2010, 1:48 AM
Ext.getCmp is not ~bad~, it's just a tool. If you use it in the wrong way, then it is bad. As the name suggests, it returns you a component based on some global identifier. This means every identifier for every component needs to be unique.

Let's say you're writing a class, some panel that you plan to use in multiple spots in your application:



MyPanel = Ext.extend(Ext.Panel, {
// ...
new Ext.List({
id: 'foo'
});
new Ext.Carousel({
id: 'bar'
});
});


What happens when you create a second instance? It's like a division by zero! Similarly, one could argue it also breaks encapsulation, since you just have this global dictionary of objects.

If you're writing applications, you'll come up with better and neater ways to reference your components, because you'll see that getCmp isn't really suitable in all cases. But it's not bad.

gabrielstuff
11 Oct 2010, 2:05 AM
Ok everything you said make sense... Thank you. But actually, why should one use ids for something that he will reuse ?
What about the fact that a "id" is unique ?

Well, things are messed up now :(

willi
11 Oct 2010, 4:20 AM
Thanks for your quick reply and explanation. I think I understand so far. But could you please give us also an example on how the ...
neater ways to reference your components ... could look like?