-
Notifications
You must be signed in to change notification settings - Fork 75
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
Event + CustomEvent in all environments #46
Comments
I hope to have a custom event shim at some point, either here or in a helper library, but in the meantime the CustomEvent from event-target-shim works! |
I don't see |
Ahh I assumed we were pulling them from EventTargetShim but they’re from JSDOM 🤔 |
yah - JSDOM does a lot for us in tests :)
We'd then need to have a helper module that does something like this: // CustomEvent.js
const getCustomEventClass = () => {
const isBrowser = () => typeof window === 'object';
if (isBrowser()) {
return CustomEvent; // the browser's class
}
return NodeCustomEvent // our custom class
}
export default getEventClass(); then you'd do something like |
I'm working on a fork of |
@ryhinchey Yeah, one of the things I didn’t like about the Also, you might want to check out Deno’s implementation of EventTargets and events if you’re thinking about this (https://github.com/denoland/deno/blob/master/cli/js/web/event_target.ts). I think it’s more rigorous, and it’s written in TypeScript already, which is nice. Also, I’m curious to hear your thoughts on my proposal that we dispatch any |
An interesting pull request from Node.js |
Note that in the PRs current state, the |
@jasnell That’s interesting! I worry about node having to ship a non-standard dispatchEvent in perpetuity but I understand why’d you make that decision. I know first-hand that the |
I managed to implement an EventTarget with capturing and bubbling for 0.2.0, without having to define an Event/CustomEvent class. I think Crank’s philosophy RE Event/CustomEvent is going to be bring your own. Not sure how much work that entails but could be a fun little project. Alternatively using the Event classes from JSDom seems to be fine, though that library is a little heavyweight if you just want the Event class. |
Currently
new CustomEvent
will only work in the browser. I see a need to have an implementation that works in node as well. The rest of the event system in crank works in node and reusing events between the browser and node could be really helpful down the road for server side rendering.I'm happy to work on a PR for it!
The text was updated successfully, but these errors were encountered: