diff --git a/spec/observables/fromEvent-spec.ts b/spec/observables/fromEvent-spec.ts index 4f599252aa..893f66f6cd 100644 --- a/spec/observables/fromEvent-spec.ts +++ b/spec/observables/fromEvent-spec.ts @@ -178,6 +178,29 @@ describe('fromEvent', () => { send('test'); }); + it('should emit multiple arguments from event as an array', (done: MochaDone) => { + let send; + const obj = { + on: (name: string, handler: Function) => { + send = handler; + }, + off: () => { + //noop + } + }; + + fromEvent(obj, 'click').take(1) + .subscribe((e: any) => { + expect(e).to.deep.equal([1, 2, 3]); + }, (err: any) => { + done(new Error('should not be called')); + }, () => { + done(); + }); + + send(1, 2, 3); + }); + it('should not throw an exception calling toString on obj with a null prototype', (done: MochaDone) => { // NOTE: Can not test with Object.create(null) or `class Foo extends null` // due to TypeScript bug. https://github.com/Microsoft/TypeScript/issues/1108 diff --git a/src/internal/observable/fromEvent.ts b/src/internal/observable/fromEvent.ts index 96e8c954d4..4a69a287ba 100644 --- a/src/internal/observable/fromEvent.ts +++ b/src/internal/observable/fromEvent.ts @@ -144,7 +144,13 @@ export function fromEvent( ): Observable { return new Observable(subscriber => { - const handler = (e: T) => subscriber.next(e); + function handler(e: T) { + if (arguments.length > 1) { + subscriber.next(Array.prototype.slice.call(arguments)); + } else { + subscriber.next(e); + } + } setupSubscription(target, eventName, handler, subscriber, options as EventListenerOptions); }); }