   cancelable_and_retrivable_callbacks,
   removed } = require './util'
 { isArray } = Array
+
+SHARED = ['parent_done', 'insert', 'replace', 'done']
 
 EVENTS = [
     'add', 'end'

defaultfn = {}
EVENTS.forEach (e) ->
    defaultfn[e] = -> throw new Error "no specific fn for #{e} defined" # dummy


class BrowserAdapter


    onremove: (el, opts) ->
        @fn.remove(el, opts)
        el._browser?.destroy(opts)
        delete el._browser unless opts.soft

    # ready callbacks

    insert_callback: (el) ->
        @fn.add(el.parent, el)
        el._browser.ready?(el)
        el._browser.ready = yes
        el._browser.insert = yes

    parent_done_callback: (el) ->
        if el.parent is el.parent.builder
            bool = (not el.parent.parent? or
                       (el.parent.parent is el.parent.parent?.builder and # FIXME recursive?
                        el.parent.parent?._browser?.insert is true))
            if bool and el.parent._browser?.insert is true
                @animation.push(el._browser.insert)
            else
                el._browser.insert?()
        else
            @animation.push(el._browser.insert)

    replace_callback: (oldtag, newtag) ->
        @fn.replace(oldtag, newtag)
