diff --git a/goldens/public-api/core/core.d.ts b/goldens/public-api/core/core.d.ts index 2ee602f7ac..7dd098bd1a 100644 --- a/goldens/public-api/core/core.d.ts +++ b/goldens/public-api/core/core.d.ts @@ -313,12 +313,18 @@ export declare class ErrorHandler { handleError(error: any): void; } -export declare class EventEmitter extends Subject { - constructor(isAsync?: boolean); +export declare interface EventEmitter extends Subject { + new (isAsync?: boolean): EventEmitter; emit(value?: T): void; subscribe(generatorOrNext?: any, error?: any, complete?: any): Subscription; } +export declare const EventEmitter: { + new (isAsync?: boolean): EventEmitter; + new (isAsync?: boolean): EventEmitter; + readonly prototype: EventEmitter; +}; + export declare interface ExistingProvider extends ExistingSansProvider { multi?: boolean; provide: any; diff --git a/packages/core/src/event_emitter.ts b/packages/core/src/event_emitter.ts index 95a3a249d5..0fe1e14b2e 100644 --- a/packages/core/src/event_emitter.ts +++ b/packages/core/src/event_emitter.ts @@ -61,32 +61,26 @@ import {Subject, Subscription} from 'rxjs'; * @see [Observables in Angular](guide/observables-in-angular) * @publicApi */ -export class EventEmitter extends Subject { +export interface EventEmitter extends Subject { /** * @internal */ - __isAsync: boolean; // tslint:disable-line + __isAsync: boolean; /** * Creates an instance of this class that can * deliver events synchronously or asynchronously. * - * @param isAsync When true, deliver events asynchronously. + * @param [isAsync=false] When true, deliver events asynchronously. * */ - constructor(isAsync: boolean = false) { - super(); - this.__isAsync = isAsync; - } + new(isAsync?: boolean): EventEmitter; /** * Emits an event containing a given value. * @param value The value to emit. */ - emit(value?: T) { - super.next(value); - } - + emit(value?: T): void; /** * Registers handlers for events emitted by this instance. * @param generatorOrNext When supplied, a custom handler for emitted events. @@ -95,6 +89,21 @@ export class EventEmitter extends Subject { * @param complete When supplied, a custom handler for a completion * notification from this emitter. */ + subscribe(generatorOrNext?: any, error?: any, complete?: any): Subscription; +} + +class EventEmitter_ extends Subject { + __isAsync: boolean; // tslint:disable-line + + constructor(isAsync: boolean = false) { + super(); + this.__isAsync = isAsync; + } + + emit(value?: any) { + super.next(value); + } + subscribe(generatorOrNext?: any, error?: any, complete?: any): Subscription { let schedulerFn: (t: any) => any; let errorFn = (err: any): any => null; @@ -155,3 +164,11 @@ export class EventEmitter extends Subject { return sink; } } + +/** + * @publicApi + */ +export const EventEmitter: { + new (isAsync?: boolean): EventEmitter; new(isAsync?: boolean): EventEmitter; + readonly prototype: EventEmitter; +} = EventEmitter_ as any;