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 #3413

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 @@ -129,16 +129,17 @@ describe('Observable.fromEvent', () => {
expect(subscribe).to.throw(TypeError, 'Invalid event target');
});

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 @@ -149,7 +150,8 @@ describe('Observable.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/observable/FromEventObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
} else if (isJQueryStyleEventEmitter(sourceObj)) {
const source = sourceObj;
sourceObj.on(eventName, handler);
Expand Down