incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Filip Maj (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-514) Do we need to monkey patch addEventListener()?
Date Wed, 02 May 2012 21:42:50 GMT

    [ https://issues.apache.org/jira/browse/CB-514?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13266936#comment-13266936
] 

Filip Maj commented on CB-514:
------------------------------

The original implementation of this API was based on this version of the spec:

http://www.w3.org/TR/2011/WD-battery-status-20110602/

... which only existed on {{window}}.

However this is only one example where we need to keep track of the number of handlers to
events on {{window}} and {{document}}:

 * [keeping track of back button handlers on Android|https://github.com/apache/incubator-cordova-js/blob/master/lib/android/platform.js#L35-L48]
 * [keeping track of all hardware button handlers on BlackBerry|https://github.com/apache/incubator-cordova-js/blob/master/lib/blackberry/platform.js#L46-L63]
 * [keeping track of resume and pause events on BlackBerry|https://github.com/apache/incubator-cordova-js/blob/master/lib/blackberry/platform.js#L86-L138]
 * [keeping track of back button handlers on WP7|https://github.com/apache/incubator-cordova-js/blob/master/lib/wp7/platform.js#L20-L32]

... think that's it.
                
> Do we need to monkey patch addEventListener()?
> ----------------------------------------------
>
>                 Key: CB-514
>                 URL: https://issues.apache.org/jira/browse/CB-514
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: CordovaJS
>            Reporter: Patrick Mueller
>            Assignee: Filip Maj
>
> discussion here: http://markmail.org/message/mghdkbumdyjhmaye
> I noticed in cordova.js we override the following messages on window/document:
> {noformat}
> document.addEventListener = function(evt, handler, capture) {...}
> window.addEventListener = function(evt, handler, capture) {...}
> document.removeEventListener = function(evt, handler, capture) {...}
> window.removeEventListener = function(evt, handler, capture) {...}
> {noformat}
> aka as "monkey patching".  
> Apparently, we aren't sure why we're doing this.  My guess is that we've done this in
the past when dispatching user-land events wasn't possible, and so trapping listeners was
the only way to get the listeners so you could send them events.
> It would be nice to remove this monkey patching, if we can, by using:
> {noformat}
> event = document.createEvent('Events')
> event.initEvent(blah)
> window.dispatchEvent(event)
> // or document.dispatchEvent(event)
> {noformat}
> We'll need to figure out if this works on all our platforms.  Even if it doesn't work
on all of them, I think we should only use monkey patching on platforms that we have to.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message