diff --git a/lib/core/src/helpers/event.ts b/lib/core/src/helpers/event.ts index 090902b58c..088d230a73 100644 --- a/lib/core/src/helpers/event.ts +++ b/lib/core/src/helpers/event.ts @@ -13,14 +13,16 @@ declare module 'cash-dom' { } /* Extend as $.Event() to create custom event for cash. */ -$.Event = (event: string, data?: unknown): CashEvent => { - const [name, ...namespaces] = event.split('.'); - const eventObject = new Event(name, { - bubbles: true, - cancelable: true, - }); - (eventObject as Event & {namespace: string}).namespace = namespaces.join('.'); - (eventObject as Event & {___ot: string}).___ot = name; - (eventObject as Event & {___td: unknown}).___td = data; - return eventObject as unknown as CashEvent; -}; +if (!$.Event) { + $.Event = (event: string, data?: unknown): CashEvent => { + const [name, ...namespaces] = event.split('.'); + const eventObject = new Event(name, { + bubbles: true, + cancelable: true, + }); + (eventObject as Event & {namespace: string}).namespace = namespaces.join('.'); + (eventObject as Event & {___ot: string}).___ot = name; + (eventObject as Event & {___td: unknown}).___td = data; + return eventObject as unknown as CashEvent; + }; +}