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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions spec/observables/fromEvent-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,17 @@ describe('fromEvent', () => {
});
});

it('should pass through options to addEventListener', () => {
let actualOptions;
it('should pass through options to addEventListener and removeEventListener', () => {
let onOptions;
let offOptions;
const expectedOptions = { capture: true, passive: true };

const obj = {
addEventListener: (a: string, b: EventListenerOrEventListenerObject, c?: any) => {
actualOptions = c;
onOptions = c;
},
removeEventListener: (a: string, b: EventListenerOrEventListenerObject, c?: any) => {
//noop
offOptions = c;
}
};

Expand All @@ -152,7 +153,8 @@ describe('fromEvent', () => {

subscription.unsubscribe();

expect(actualOptions).to.equal(expectedOptions);
expect(onOptions).to.equal(expectedOptions);
expect(offOptions).to.equal(expectedOptions);
});

it('should pass through events that occur', (done: MochaDone) => {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/observable/fromEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function setupSubscription<T>(sourceObj: EventTargetLike, eventName: string,
} else if (isEventTarget(sourceObj)) {
const source = sourceObj;
sourceObj.addEventListener(eventName, handler as EventListener, options);
unsubscribe = () => source.removeEventListener(eventName, handler as EventListener);
unsubscribe = () => source.removeEventListener(eventName, handler as EventListener, options);
} else if (isJQueryStyleEventEmitter(sourceObj)) {
const source = sourceObj;
sourceObj.on(eventName, handler);
Expand Down