var DataSet = require("data-set")

var multipleEvents = require("./multiple-events.js")

module.exports = getListener

function getListener(surface, id, target, type) {
    if (target === null) {
        return null
    }

    var ds = DataSet(target)
    var events = ds[type]
    var allEvents = ds.event

    var handler = events && events[id]
    var allHandler = allEvents && allEvents[id]

    if (!handler && !allHandler) {
        return getListener(surface, id,
            surface.getParent(target), type)
    }

    handler = handler || allHandler
    if (handler && allHandler) {
        handler = multipleEvents(handler, allHandler)
    }

    return new Listener(target, handler)
}

function Listener(target, handler) {
    this.currentTarget = target
    this.handler = handler
}

@@ -520,44 +520,8 @@
  %7D%0A%0A
-    handler = handler %7C%7C allHandler%0A
     
@@ -604,24 +604,60 @@
 ndler)%0A    %7D
+%0A    handler = handler %7C%7C allHandler
 %0A%0A    return

fix multi call bug