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

Peter commented on CB-4819:
---------------------------

Thankyou for the reply. Unfortunately, none of the functionality which you 
describe matches what I see in practice.

There really wasn't much IAB.removeEventListener test cases in the mobile-spec 
so I've augmented the inappbrowser/index.html just to experiment with the 
add/remove eventListener to see what happens. Note, I've put an 'alert' in each 
of the handlers to see when they get called. If these tests are flawed please 
tell me.

Anyway, we observed the following when running the White Listed URL test 
'Target=Blank InAppBrowser'

*CASE 1: Register multiple callbacks for same eventName*
{code}
iab.addEventListener('loadstart', logEvent, false);
iab.addEventListener('loadstart', logEvent2);
{code}
Result:
- hello from logevent
- hello from logevent2
- hello from logevent
- hello from logevent2

Notice both callbacks get called on loadstart.
(I do not yet know why the callbacks were called multiple times, but I think it 
is unrelated to this particular JIRA.)

*Conclusion:*
_It is OK to have multiple callbacks for same event._

*CASE 2: Multiple callbacks for same eventName. Then remove a one of them*

*2a - remove one*
{code}
iab.addEventListener('loadstart', logEvent, false);
iab.addEventListener('loadstart', logEvent2);
iab.removeEventListener('loadstart', logEvent2);
{code}
Result:
- hello from logevent
- hello from logevent

Notice only logEvent is still called. logEvent2 is not.
(I do not yet know why the callback was called multiple times, but I think it 
is unrelated to this particular JIRA.)

*2b - remove other one*
{code}
iab.addEventListener('loadstart', logEvent, false);
iab.addEventListener('loadstart', logEvent2);
iab.removeEventListener('loadstart', logEvent);
{code}
Result:
- hello from logevent2
- hello from logevent2

Notice only logEvent2 is still called. logEvent is not.
(I do not yet know why the callback was called multiple times, but I think it 
is unrelated to this particular JIRA.)

*Conclusion:*
_The callback parameter is important. It identifies which previously registered 
function to remove. Any other callback for that event remain active._


*CASE 3: Does callback get fired when event gets removed?*

*3a - remove a previously registered one*
This is same as case 2a/2b. 
Result:
No. The "removed" callback is not called.

*3b - remove some arbitrary callback*
{code}
iab.addEventListener('loadstart', logEvent, false);
iab.removeEventListener('loadstart', logEvent3);
{code}
- hello from logEvent
- hello from logEvent

Result:
Notice logEvent3 is not called.
(I do not yet know why the callback was called multiple times, but I think it 
is unrelated to this particular JIRA.)

*Conclusion:*
_Calling removeEventLister does not fire the callback._

                
> InAppBrowser.removeEventListener - description of callback parameter
> --------------------------------------------------------------------
>
>                 Key: CB-4819
>                 URL: https://issues.apache.org/jira/browse/CB-4819
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Docs
>    Affects Versions: 2.9.0
>            Reporter: Peter
>            Assignee: Michael Brooks
>            Priority: Minor
>
> The documentation for removeEventListener seems like a cut/paste error from 
> addEventListener.
> http://cordova.apache.org/docs/en/3.0.0/cordova_inappbrowser_inappbrowser.md.html#removeEventListener
>  says:
> {quote}
> *callback:* the function to execute when the event fires. The function is 
> passed an InAppBrowserEvent object.
> {quote}
> It might be better described as something like:
> {quote}
> *callback:* the function to be removed, which was previously registered for 
> this event by addEventListener
> {quote}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to