From 796b5d55f88607b4a01754386edeb5e637e068ec Mon Sep 17 00:00:00 2001 From: bencmbrook Date: Mon, 10 Jul 2023 14:56:31 -0700 Subject: [PATCH] Add Transcend event target --- src/components/App.tsx | 3 ++- src/event-target.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/event-target.ts diff --git a/src/components/App.tsx b/src/components/App.tsx index ad8d2ea5..a413c2ac 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -19,6 +19,7 @@ import { ConsentManagerLanguageKey } from '@transcend-io/internationalization'; import { CONSENT_MANAGER_SUPPORTED_LANGUAGES } from '../i18n'; import { makeConsentManagerAPI } from '../api'; +import { TranscendEventTarget } from '../event-target'; // TODO: https://transcend.height.app/T-13483 // Fix IntlProvider JSX types @@ -26,7 +27,7 @@ import { makeConsentManagerAPI } from '../api'; const IntlProvider = _IntlProvider as any; // Create `transcend` eventTarget on the global scope so this isn't derefenced on the next render of App -const eventTarget = new EventTarget(); +const eventTarget = new TranscendEventTarget(); /** * Top layer concerned with data, not presentation diff --git a/src/event-target.ts b/src/event-target.ts new file mode 100644 index 00000000..b5a8bb26 --- /dev/null +++ b/src/event-target.ts @@ -0,0 +1,20 @@ +/** + * Extend EventTarget to include the Transcend toStringTag + */ +export class TranscendEventTarget extends EventTarget { + #stringTag: string = 'Transcend'; + + get [Symbol.toStringTag]() { + console.log(this.#stringTag); + return this.#stringTag; + } + + // Allow airgap.js code to overwrite [Symbol.toStringTag] + set [Symbol.toStringTag](updatedStringTag: string) { + this.#stringTag = updatedStringTag; + } + + constructor(...args: ConstructorParameters) { + super(...args); + } +}