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

Locally defined script tag within tags #9453

Open
OTheNonE opened this issue Nov 14, 2023 · 3 comments
Open

Locally defined script tag within tags #9453

OTheNonE opened this issue Nov 14, 2023 · 3 comments

Comments

@OTheNonE
Copy link

OTheNonE commented Nov 14, 2023

Describe the problem

#snippet is a feature i’ve really wanted, great news! Related to this feature, is that i’ve found myself defining many locally used objects inside the global script tag in a +page, which could just as well been defined locally in a tag and only be used there. I have no idea about the complications of this, but may this be considered in some version of Svelte?

Describe the proposed solution

It would be awesome to define local script tags or just local variables, either within a tag in a +page or a #snippet, or both. Here is a small example: https://svelte.dev/repl/8492f743da224435b860620f74096991?version=4.2.3

Alternatives considered

Components can be used to solve this, but I think these would not fit these cases properly.

Importance

nice to have

@Conduitry
Copy link
Member

Have you seen https://svelte.dev/docs/special-tags#const ?

Non-top-level <script> tags aren't something we want to change the behavior of, because those are currently used for injecting that literal <script> tag at that point in the DOM, as an escape hatch for various situations.

@OTheNonE
Copy link
Author

Yes, i am aware of {#const ... }, but the purpose of this is only to make a shorthand calculation or something similar, right? When defining a {#const ... } variable locally, it is dependent on other variables, and is non-editable. I would like an editable locally defined variable. (I have added a REPL example in my original comment).

@david-plugge
Copy link

I think that you should create a new component for that kind of stuff

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

3 participants