Skip to content

Commit

Permalink
Merge pull request #3350 from cartant/issue-3349
Browse files Browse the repository at this point in the history
fix(fromEvent): pass options in unsubscribe
  • Loading branch information
benlesh authored Mar 8, 2018
2 parents fb78357 + f1872b0 commit 9d83f0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
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

0 comments on commit 9d83f0a

Please sign in to comment.