 # TODO listen for dom events to know when a dom manipulation is ready
 # TODO mit canvas tag kommt man direkt auf die browser render ticks.
 
+removed = (el) ->
+    el.closed is "removed"
 
 # delay or invoke job immediately
 delay = (job) ->
+    return if removed this
     # only when tag is ready
     if @_dom?
         do job

                parent._dom.push(el._dom)
            else
                nextAnimationFrame ->
                    parent._dom.appendChild(el._dom)

    tpl.on 'close', (el) ->
        # FIXME hm, ... namespace handling should be in asyncxml

    tpl.on 'replace', (el, tag) ->
        delay.call el, ->
            nextAnimationFrame ->
                return if removed el
                _dom = tag._dom ? tag
                return unless _dom?.length > 0
                el.parent?._dom?.replaceChild(_dom)
