incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Mueller <pmue...@gmail.com>
Subject why are we monkey patching addEventListener()?
Date Fri, 13 Apr 2012 15:32:22 GMT
Question about:


https://github.com/apache/incubator-cordova-js/blob/master/lib/cordova.js

specifically:

    document.addEventListener = function(evt, handler, capture) {...}
    window.addEventListener = function(evt, handler, capture) {...}
    document.removeEventListener = function(evt, handler, capture) {...}
    window.removeEventListener = function(evt, handler, capture) {...}

The question is:

    GREAT ODIN'S RAVEN WHY ARE WE DOING THIS?

Does the following just not work for user-created events?

    event = document.createEvent('Events')
    event.initEvent(blah)

    window.dispatchEvent(event)
    // or document.dispatchEvent(event)

I dislike monkey patching, and my natural inclination is to blame it when
you see problem reports of the ilk "I never got the deviceready (or
whatever) message".

OTOH, I do monkey patch these in weinre (I think - I used to, or something)
so I can do some diagnostic work

If we have to, we have to.

But if we don't have to, I'd prefer we didn't.

If we have to on some platform, but not others, I'd prefer we only do it on
platforms that we need to do it.

If we're doing it because there's (essentially) a magic linkage between
these events and channels, and we muck with the "handlers" via the channels
because they're magically linked, I'd prefer we didn't do that.

-- 
Patrick Mueller
http://muellerware.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message