Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE 2: Should globalThis be required to extend from EventTarget? #16

Open
XadillaX opened this issue May 19, 2022 · 7 comments
Open

Comments

@XadillaX
Copy link

XadillaX commented May 19, 2022

https://proposal-common-min-api.deno.dev/#issue-69352234

I think globalThis SHOULD extend from EventTarget. Or at lease there will be one EventTarget instance, and globalThis should mount that instance's *EventListener(), dispatchEvent().

And also, I think the lifetime and events (install, activate, fetch, etc.) also should be embodied.

@ljharb
Copy link
Member

ljharb commented May 19, 2022

That seems like something that would conflict pretty heavily with browsers.

@lucacasonato
Copy link
Member

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.

@ljharb
Copy link
Member

ljharb commented May 19, 2022

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?

@lucacasonato
Copy link
Member

Deno uses the global event target for "load" and "unload" events for example. CFW uses it for the global "fetch" event.

@XadillaX
Copy link
Author

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?

fetch event in service worker.

@JakeChampion
Copy link

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

@jasnell
Copy link
Contributor

jasnell commented Jun 1, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants