views:

1709

answers:

2

I have a question concerning the performance, reliability, and best practice method of using Extjs's update() method, versus directly updating the innerHTML of the dom of an Ext element.

Consider the two statements:

Ext.fly('element-id').dom.innerHTML = 'Welcome, Dude!';

and

Ext.fly('element.id').update('Welcome, Dude!', false);

I don't need to eval() any script, and I'm certain that update() takes into consideration any browser quirks.


Also, does anyone know if using:

Ext.fly('element-id').dom.innerHTML

is the same as

d.getElementById('element-id').innerHTML

?
Browser and platform compatibility are important, and if the two are fundamentally the same, then ditching Ext.element.dom.innerHTML altogether for update() would probably be my best solution.

Thanks in advance for your help,

Brian

+2  A: 

If you do not need to load scripts dynamically into your updated html or process a callback after the update, then the two methods you've outlined are equivalent. The bulk of the code in update() adds the script loading and callback capabilities. Internally, it simply sets the innerHTML to do the content replacement.

Ext.fly().dom returns a plain DOM node, so yes, it is equivalent to the result of getElementById() in terms of the node it points to. The only subtlety to understand is the difference between Ext.fly() and Ext.get(). Ext.fly() returns a shared instance of the node wrapper object (a flyweight). As such, that instance might later point to a different node behind the scenes if any other code calls Ext.fly(), including internal Ext code. As such, the result of a call to Ext.fly() should only be used for atomic operations and not reused as a long-lived object. Ext.get().dom on the other hand returns a new, unique object instance, and in that sense, would be more like getElementById().

bmoeskau
So, to put it basically, unless I'm wanting to process a callback or eval some scripts, then using `update()` is more or less overkill. Am I understanding that correctly?My main concern is browser compatibility. So in those terms, does `update()` have any advantage over `Ext.fly().dom`?Thanks!!
DondeEstaMiCulo
It makes no difference. It's not overkill -- it's exactly the same. There is no difference in compatibility.
bmoeskau
+1  A: 

I think you answered your own question: "Browser and platform compatibility are important, and if the two are fundamentally the same, then ditching Ext.element.dom.innerHTML altogether for update() would probably be my best solution." JS libraries are intended (in part) to abstract browser differences; update is an example.

@bmoeskau wrote above, update() provides additional functionality that you don't need right for your current problem. Nevertheless, update is a good choice.

Upper Stage