Skip to content

Commit

Permalink
Add Transcend event target
Browse files Browse the repository at this point in the history
  • Loading branch information
bencmbrook committed Jul 10, 2023
1 parent c547b98 commit 796b5d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ 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
// eslint-disable-next-line @typescript-eslint/no-explicit-any
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
Expand Down
20 changes: 20 additions & 0 deletions src/event-target.ts
Original file line number Diff line number Diff line change
@@ -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<typeof EventTarget>) {
super(...args);
}
}

0 comments on commit 796b5d5

Please sign in to comment.