Open XadillaX opened 2 years ago
That seems like something that would conflict pretty heavily with browsers.
That seems like something that would conflict pretty heavily with browsers.
Why? In all three primary browser realm types (main thread, workers, service workers etc), globalThis
has a prototype that extends EventTarget
.
ah, i think i was confusing it with event emitters.
It makes sense that there's a global addEventListener
, for example, in the browser, because the DOM is ever-present there. That's not the case outside the browser. What types of targets and events would addEventListener
interact with outside the browser?
Deno uses the global event target for "load" and "unload" events for example. CFW uses it for the global "fetch" event.
ah, i think i was confusing it with event emitters.
It makes sense that there's a global
addEventListener
, for example, in the browser, because the DOM is ever-present there. That's not the case outside the browser. What types of targets and events wouldaddEventListener
interact with outside the browser?
fetch
event in service worker.
Deno uses the global event target for "load" and "unload" events for example. CFW uses it for the global "fetch" event.
Fastly also use it for the global "fetch" event -- https://js-compute-reference-docs.edgecompute.app/index.html#addeventlistener
We discussed this issue on the last wintercg call. Where we landed is that the idea that globalThis
should extend from EventTarget
would qualify as "normative optional"... that is, it is not something that should be required of all Web-interoperable runtimes but should behave consistently for those that do implement it. As opposed to including it in the common minimum API doc, the idea will be to write up a separate note that describes the expected interoperable behavior.
I think
globalThis
SHOULD extend fromEventTarget
. Or at lease there will be oneEventTarget
instance, andglobalThis
should mount that instance's*EventListener()
,dispatchEvent()
.And also, I think the lifetime and events (
install
,activate
,fetch
, etc.) also should be embodied.