-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Feature Request: "module" context allowing access to component Constructor #3010
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
I'd definitely not rewrite But I don't see much of a problem with providing access to the component class through a non-exported If someone created their own variables with a clashing name, we could simply not emit the alias. But instead of mangling internal names like we do for everything else, if they just referenced the alias we wouldn't do anything, giving users direct access to the generated I'd definitely back a feature like that. When not in use the alias would be tree-shakeable anyway... But yeah, I don't think Rich likes the idea of giving access to a component's instance/class from within the component's context in general... In the meanwhile, if you're okay with some dirtiness, have a look at this hacky async registry implementation that works in current-svelte. |
Any update on this proposal? I've run into a situation where this would be particularly useful, where I'd like to be able to export the component itself, as well as some complementary config, from module context. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
In svelte v2 our testing setup uses
jest
withpuppeteer
, and takes advantage of thesetup
hook to be able to have a reference to the component constructor so we can register them into a globally-available repository to ease accessing from jest.Here's a brief example, it's a bit spread out but hopefully gets the idea across.
https://gist.github.com/tivac/38fe7fd0f8eb8335dfc05f8f5d375185
In v3 there's
<script context="module">
but it doesn't have any access to the component's constructor likesetup
did. That makes me sad, because it means we don't have a great way to test our v3 components from within puppeteer beyond creating a manual central repository that includes them all or something.I'm not totally sure how I'd expect accessing the component constructor from
<script context="module">
to work. Maybe it could rewritethis
or some sort of other special named thing? I know Rich has avoided special functions in the past so importing it fromsvelte/constructor
or something seems right out.The text was updated successfully, but these errors were encountered: