XBL bound tag in a template DOM timing issue

dave fletcher <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xpfe
Message-ID <CAAL67RyB-QR5jz5xWP54=qWoBNKzhMkjvB4FOZj5ydqKDGXvcA@mail.gmail.com>
Hi all. Having what I believe is a timing issue here.

<listbox datasources='rdf:null' ref='rdf:null' flex='1'
menu-label='Icon view' class='datasource-library-keyframes'>
  <template>
    <listitem uri='rdf:*' class='large-icon-wrapper'><listcell>
      <vbox>
        <svgloader src='rdf:http://example.com/app/1.0#file'
object='rdf:http://example.com/app/1.0#keyframe' width='64'
height='64' />
        <xul:label value='rdf:http://example.com/app/1.0#keyframe' />
      </vbox>
    </listcell></listitem>
  </template>
</listbox>

(note: datasources and ref attributes of listbox are set in JS on window load)

<binding id='svgloader'>
  <content><svg:svg /></content>
  <implementation>
    <constructor><![CDATA[
     ...
      this.getAttribute('src'); this.getAttribute('object'); // <-- problem code
     ...
    ]]></constructor>
  </implementation>	
</binding>

So the issue is with the two attributes with the comment labeled
"problem code" above. Sometimes these attributes read the value from
the attached RDF just fine. Other times, I get back an empty string.
It seems fairly random whether it works or not.

My hackish fix is:

<constructor><![CDATA[
    var svgwrapper = this;
    window.setTimeout(function() {
      svgwrapper.getAttribute('src');
svgwrapper.getAttribute('object'); // <-- works!
    }, 50, []);
]]></constructor>

I'm thinking the only way to do this correctly is to climb the parents
of the bound element, looking for a .builder property. If I find one,
addListener(), and wait for didRebuild() to get called. If I don't
find one, then I can call getAttribute() immediately.

Is that really the solution? Seems like a ton of code just to support
attributes that happen to be in a template.

Thanks in advance for any advice!

Cheers,

--fletch
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.