Skip to content

Commit

Permalink
Make globalThis inherit from EventTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Oct 21, 2023
1 parent 6bff6a8 commit 7f7d961
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-lobsters-peel.md
@@ -0,0 +1,5 @@
---
'nxjs-runtime': patch
---

Make `globalThis` inherit from `EventTarget`
13 changes: 13 additions & 0 deletions packages/runtime/src/index.ts
Expand Up @@ -112,6 +112,19 @@ function touchIsEqual(a: Touch, b: Touch) {

const btnPlus = 1 << 10; ///< Plus button

// Make `globalThis` inherit from `EventTarget`
Object.setPrototypeOf(globalThis, EventTarget.prototype);
EventTarget.call(globalThis);
def(
'addEventListener',
EventTarget.prototype.addEventListener.bind(globalThis)
);
def(
'removeEventListener',
EventTarget.prototype.removeEventListener.bind(globalThis)
);
def('dispatchEvent', EventTarget.prototype.dispatchEvent.bind(globalThis));

Switch.addEventListener('frame', (event) => {
const {
keyboardInitialized,
Expand Down

0 comments on commit 7f7d961

Please sign in to comment.