Skip to content

Commit 78f0899

Browse files
rubennortefacebook-github-bot
authored andcommitted
Use React Native built-in definitions for Event and EventTarget in Fantom (#53362)
Summary: Pull Request resolved: #53362 Changelog: [internal] This just replaces the polyfills for `Event` and `EventTarget` that we're defining inline in Fantom with the implementations that already exist in RN. Reviewed By: javache Differential Revision: D80612067 fbshipit-source-id: 047c8f12cbb1f4afea2d05a5a1235d9dff2e25f9
1 parent 8480386 commit 78f0899

1 file changed

Lines changed: 4 additions & 46 deletions

File tree

private/react-native-fantom/src/index.js

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -577,59 +577,17 @@ export type {
577577
*/
578578

579579
if (typeof global.Event === 'undefined') {
580-
global.Event = class Event {
581-
constructor() {}
582-
};
580+
global.Event =
581+
require('react-native/src/private/webapis/dom/events/Event').default;
583582
} else {
584583
console.warn(
585584
'The global Event class is already defined. If this API is already defined by React Native, you might want to remove this logic.',
586585
);
587586
}
588587

589588
if (typeof global.EventTarget === 'undefined') {
590-
global.EventTarget = class EventTarget {
591-
listeners: $FlowFixMe;
592-
593-
constructor() {
594-
this.listeners = {};
595-
}
596-
597-
addEventListener(type: string, cb: () => void) {
598-
if (!(type in this.listeners)) {
599-
this.listeners[type] = [];
600-
}
601-
this.listeners[type].push(cb);
602-
}
603-
604-
removeEventListener(type: string, cb: () => void): void {
605-
if (!(type in this.listeners)) {
606-
return;
607-
}
608-
let handlers = this.listeners[type];
609-
for (let i in handlers) {
610-
if (cb === handlers[i]) {
611-
handlers.splice(i, 1);
612-
return;
613-
}
614-
}
615-
}
616-
617-
dispatchEvent(type: string, event: Event) {
618-
if (!(type in this.listeners)) {
619-
return;
620-
}
621-
let handlers = this.listeners[type];
622-
for (let i in handlers) {
623-
handlers[i].call(this, event);
624-
}
625-
}
626-
627-
clearEventListeners() {
628-
for (let i in this.listeners) {
629-
delete this.listeners[i];
630-
}
631-
}
632-
};
589+
global.EventTarget =
590+
require('react-native/src/private/webapis/dom/events/EventTarget').default;
633591
} else {
634592
console.warn(
635593
'The global Event class is already defined. If this API is already defined by React Native, you might want to remove this logic.',

0 commit comments

Comments
 (0)