-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Get a reference to the "root" element when creating a "custom element" #3593
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
Comments
The createElementEventDispatcher could look something like this.. |
This is probably related to #3119 |
Can I contribute in the clarification somehow? @Conduitry |
What I'm trying to achieve is to raise/dispatch a custom event from a web component. As I see it 2 possible solutions
|
Related #3091 |
When trying to create a
CustomEvent
in a custom element I want thedispatcher
of the event to be the custom element. (I have tried to use thecreateEventDispatcher
, but that did not work).E.G
To be able to do this right now, you have to get a reference to the current my-custom-svelte-element inside your code.
What i have seen is that in the compiled code
function instance($$self, $$props, $$invalidate)
is the function that is called when initializing the component. And the$$self
is actually the right element.. But trying to access it pre compile gives me an error about $$self is not an legal param name..Trying to access just
self
actually gives me window 😄 but that I think, is an undocumented feature...To achieve what I need at this moment, a new function similar to the
createEventDispatcher
named something likecreateElementEventDispatcher
witch compiles down to something likecreateElementEventDispatcher($$self)
and inside this captures the $$self and exposes a dispatch method that matches thethis would make it easy to raise events from inside your custom element and to the DOM.
This would be a very 'narrow' solution to my problem and a more generic one would be to be able to get the reference to the
$$self
parameter.. then it would be possible to dispatch the event your self. Maybe a special directive of some kind..I think this is a really basic functionality when creating custom-elements, at least in my case where the custom elements are more like self contained widgets that needs to communicate through events and attributes.
And also very basic thing when it comes to micro front ends.
The text was updated successfully, but these errors were encountered: