PDA

View Full Version : Two flys don't make a get



gnosis
15 Aug 2007, 12:22 PM
If I'm going to just do a one-off operation on an element, I use Element.fly() to throw a function at it.
Ext.fly('theDiv').update('Blah');But if I think I'm going to use that element ever again, I stick it in a variable.
var theDiv = Ext.get('theDiv');
theDiv.update('Blah');
theDiv.insertHTML('beforeEnd', ' Blah');Is this good practice? Or should I need several uses of fly() before it's worth storing the element object?

Thanks,
G

jack.slocum
15 Aug 2007, 5:56 PM
It's fine to use the element. You can also use the fly() return value multiple times if you are doing your calls consectively (and not calling fly on other elements in between).

Animal
15 Aug 2007, 11:16 PM
It's fine to use the element. You can also use the fly() return value multiple times if you are doing your calls consectively (and not calling fly on other elements in between).

What about interruptions by events whose handlers may also use fly? I don't know how browsers handle async events, but if they check between statements for a queue of events, then expcting a shared flyweight to have the same value in 2 consecutive statements might not be safe.

jack.slocum
16 Aug 2007, 2:28 AM
JS executes a single thread at a time. Those event handlers shouldn't execute until the current running code (thread) has completed. This is also one of the reasons for occasionally needing setTimeout to defer and let other code execute to prevent unresponsive UIs.