[
https://issues.apache.org/jira/browse/CB-514?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13266896#comment-13266896
]
Filip Maj commented on CB-514:
------------------------------
I've looked into this a little bit more, and been working on a [branch in my
repo|https://github.com/filmaj/incubator-cordova-js/tree/axemonkeypatch].
I stumbled upon an issue, though. For example, in the battery API, we need to
know when the first handler to a {{window}} or {{document}} event gets added,
and when the last handler gets removed, so that we can tell the native code to
start and stop listening for battery events. I can't see a way to do that
unless we monkeypatch {{addEventListener}} et al.
Any ideas, Pat?
> 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