You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by Patrick Mueller <pm...@gmail.com> on 2012/04/13 17:32:22 UTC

why are we monkey patching addEventListener()?

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

Re: why are we monkey patching addEventListener()?

Posted by gt...@gmail.com.
I think we also monkey patch to trigger the callback for device ready via the channel. I agree it isn't the nicest way but is a low impact coupling between triggering channel events and raising dom events.
Sent on the TELUS Mobility network with BlackBerry

-----Original Message-----
From: Filip Maj <fi...@adobe.com>
Date: Sat, 14 Apr 2012 14:24:08 
To: callback-dev@incubator.apache.org<ca...@incubator.apache.org>
Reply-To: callback-dev@incubator.apache.org
Subject: Re: why are we monkey patching addEventListener()?

Disagree with your point that "we should do it different on each platform"
- at least the monkey patching is consistent on all platforms and WORKS.

On 4/14/12 2:20 PM, "Patrick Mueller" <pm...@gmail.com> wrote:

>On Sat, Apr 14, 2012 at 13:50, Filip Maj <fi...@adobe.com> wrote:
>
>> >The question is:
>> >
>> >    GREAT ODIN'S RAVEN WHY ARE WE DOING THIS?
>>
>> Because that's how we've done it since day one. That's all I've got.
>
>
>Now we got this: https://issues.apache.org/jira/browse/CB-514
>
>-- 
>Patrick Mueller
>http://muellerware.org


Re: why are we monkey patching addEventListener()?

Posted by Filip Maj <fi...@adobe.com>.
Disagree with your point that "we should do it different on each platform"
- at least the monkey patching is consistent on all platforms and WORKS.

On 4/14/12 2:20 PM, "Patrick Mueller" <pm...@gmail.com> wrote:

>On Sat, Apr 14, 2012 at 13:50, Filip Maj <fi...@adobe.com> wrote:
>
>> >The question is:
>> >
>> >    GREAT ODIN'S RAVEN WHY ARE WE DOING THIS?
>>
>> Because that's how we've done it since day one. That's all I've got.
>
>
>Now we got this: https://issues.apache.org/jira/browse/CB-514
>
>-- 
>Patrick Mueller
>http://muellerware.org


Re: why are we monkey patching addEventListener()?

Posted by Patrick Mueller <pm...@gmail.com>.
On Sat, Apr 14, 2012 at 13:50, Filip Maj <fi...@adobe.com> wrote:

> >The question is:
> >
> >    GREAT ODIN'S RAVEN WHY ARE WE DOING THIS?
>
> Because that's how we've done it since day one. That's all I've got.


Now we got this: https://issues.apache.org/jira/browse/CB-514

-- 
Patrick Mueller
http://muellerware.org

Re: why are we monkey patching addEventListener()?

Posted by Anis KADRI <an...@gmail.com>.
I used create/init/dispatchEvent as well in my implementation until I
started working with common js :)

On Sat, Apr 14, 2012 at 10:50 AM, Filip Maj <fi...@adobe.com> wrote:

>
> >The question is:
> >
> >    GREAT ODIN'S RAVEN WHY ARE WE DOING THIS?
>
> Because that's how we've done it since day one. That's all I've got.
>
> >
> >Does the following just not work for user-created events?
> >
> >    event = document.createEvent('Events')
> >    event.initEvent(blah)
> >
> >    window.dispatchEvent(event)
> >    // or document.dispatchEvent(event)
>
> Not sure, does it work across all platforms?
>
>

Re: why are we monkey patching addEventListener()?

Posted by Filip Maj <fi...@adobe.com>.
>The question is:
>
>    GREAT ODIN'S RAVEN WHY ARE WE DOING THIS?

Because that's how we've done it since day one. That's all I've got.

>
>Does the following just not work for user-created events?
>
>    event = document.createEvent('Events')
>    event.initEvent(blah)
>
>    window.dispatchEvent(event)
>    // or document.dispatchEvent(event)

Not sure, does it work across all platforms?