{"version":3,"sources":["src/common/EventSource.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,WAAW,CAAC,MAAM,SAAS,aAAa,CAAE,YAAW,YAAY,CAAC,MAAM,CAAC;IAClF,OAAO,CAAC,kBAAkB,CAAkD;IAC5E,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,cAAc,CAAkB;gBAE5B,QAAQ,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC;IAIzC,OAAO,0BAsBb;IAEM,MAAM,4DAQZ;IAEM,cAAc,oDAEpB;IAEM,UAAU,gBAEhB;IAEM,OAAO,aAGb;aAEU,QAAQ,EAAI,iBAAiB,CAAC,MAAM,CAAC;CAGnD","file":"EventSource.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport { ObjectDisposedError } from \"./Error\";\nimport { createNoDashGuid } from \"./Guid\";\nimport { IDetachable } from \"./IDetachable\";\nimport { IStringDictionary } from \"./IDictionary\";\nimport { IEventListener, IEventSource } from \"./IEventSource\";\nimport { PlatformEvent } from \"./PlatformEvent\";\n\nexport class EventSource<TEvent extends PlatformEvent> implements IEventSource<TEvent> {\n    private privEventListeners: IStringDictionary<(event: TEvent) => void> = {};\n    private privMetadata: IStringDictionary<string>;\n    private privIsDisposed: boolean = false;\n\n    constructor(metadata?: IStringDictionary<string>) {\n        this.privMetadata = metadata;\n    }\n\n    public onEvent = (event: TEvent): void => {\n        if (this.isDisposed()) {\n            throw (new ObjectDisposedError(\"EventSource\"));\n        }\n\n        if (this.metadata) {\n            for (const paramName in this.metadata) {\n                if (paramName) {\n                    if (event.metadata) {\n                        if (!event.metadata[paramName]) {\n                            event.metadata[paramName] = this.metadata[paramName];\n                        }\n                    }\n                }\n            }\n        }\n\n        for (const eventId in this.privEventListeners) {\n            if (eventId && this.privEventListeners[eventId]) {\n                this.privEventListeners[eventId](event);\n            }\n        }\n    }\n\n    public attach = (onEventCallback: (event: TEvent) => void): IDetachable => {\n        const id = createNoDashGuid();\n        this.privEventListeners[id] = onEventCallback;\n        return {\n            detach: () => {\n                delete this.privEventListeners[id];\n            },\n        };\n    }\n\n    public attachListener = (listener: IEventListener<TEvent>): IDetachable => {\n        return this.attach(listener.onEvent);\n    }\n\n    public isDisposed = (): boolean => {\n        return this.privIsDisposed;\n    }\n\n    public dispose = (): void => {\n        this.privEventListeners = null;\n        this.privIsDisposed = true;\n    }\n\n    public get metadata(): IStringDictionary<string> {\n        return this.privMetadata;\n    }\n}\n"]}