Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fromEvent): pass options in unsubscribe #3350

Merged
merged 2 commits into from
Mar 8, 2018

Conversation

cartant
Copy link
Collaborator

@cartant cartant commented Feb 27, 2018

Description:

Fixes the problem reported in #3349. In Chrome, at least, if options are passed in the call to addEventListener, but not in the call to removeEventListener, the listener is not removed.

The PR adds an expectation to an existing test and passes the options in the call to removeEventListener, too.

Related issue (if exists): #3349

@kwonoj
Copy link
Member

kwonoj commented Feb 27, 2018

So actually MDN describes this topic already: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener

While addEventListener() will let you add the same listener more than once for the same type if the options are different, the only option removeEventListener() checks is the capture/useCapture flag. Its value must match for removeEventListener() to match, but the other values don't.

It's worth noting that some browser releases have been inconsistent on this, and unless you have specific reasons otherwise, it's probably wise to use the same values used for the call to addEventListener() when calling removeEventListener().

Change looks legit to me.

@rxjs-bot
Copy link

rxjs-bot commented Feb 27, 2018

Messages
📖

CJS: 1313.3KB, global: 698.6KB (gzipped: 114.5KB), min: 135.0KB (gzipped: 29.8KB)

Generated by 🚫 dangerJS

@coveralls
Copy link

coveralls commented Feb 27, 2018

Coverage Status

Coverage remained the same at 97.517% when pulling f1872b0 on cartant:issue-3349 into 1e4ca05 on ReactiveX:master.

@@ -206,7 +206,7 @@ export class FromEventObservable<T> extends Observable<T> {
} else if (isEventTarget(sourceObj)) {
const source = sourceObj;
sourceObj.addEventListener(eventName, <EventListener>handler, <boolean>options);
unsubscribe = () => source.removeEventListener(eventName, <EventListener>handler);
unsubscribe = () => source.removeEventListener(eventName, <EventListener>handler, <boolean>options);
Copy link
Contributor

@crisbeto crisbeto Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options aren't necessarily a boolean, they can be an EventListenerOptions object as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unaware of why the boolean assertion was used in the original code's call to the addEventListener method. Perhaps the typings in an earlier version of TypeScript were not representative of the API? The current typings seem okay, so I guess this could be changed. However, it is only a type assertion and has no runtime effect.

@benlesh benlesh merged commit 9d83f0a into ReactiveX:master Mar 8, 2018
@benlesh
Copy link
Member

benlesh commented Mar 8, 2018

Thanks, @cartant! :)

@cartant
Copy link
Collaborator Author

cartant commented Mar 8, 2018

@benlesh Before I rebased this PR - to accommodate the refactorings in master - it would have be cherry-pickable into stable. Do you see any need for another PR to fix this in stable, too?

@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants