-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Proposal: Switch props from "export let" to "import let" #3454
Comments
This is invalid Javascript, and would break existing tooling. Being valid Javascript and working with existing tooling is, as I understand it, one of the goals of the Svelte project. |
@antony is correct, everything in a Svelte component's script tag has to be syntactically valid javascript. This change is not only invalid but would also be a breaking change. Whether or not this suggestion is less confusing is entirely subjective because a component doesn't import props it accepts them, control is delegated to the parent, not the other way around. |
Fair points, but I think a discussion around better semantics is still valid, even if the proposed solution isn't. What about another way of identifying props passed in vs values sent out?
|
Props passed in can be changed, for example a bound prop can mutate. Absolutely happy to have a discussion around it, like you say. The rest of your reasoning is fair - the only workable ones being the underscored ones, and I don't think that really helps imply anything, other than looking quite ugly in my opinion - and yes, it looks like poorly hiding a public variable. I have to agree with @pngwn though, in that I find the current syntax of |
|
I'm going to save everyone's time and close this issue, because I don't see any realistic prospect of this changing. This has been discussed before at considerable length, and |
Import is certainly not an option. <script>
prop type;
prop type;
prop value;
</script>
<p>
<label>{label}</label>
<input type={type} bind:value={value} />
</p> |
Describe the solution you'd like
Whilst going through the tutorial, I was confused by the same use of
export let name
for both receiving in props from parent, and passing value up to the parent through bind. It seems that receiving props in using "export let" doesn't really have the right connotation.Describe alternatives you've considered
Consider changing the syntax for receiving props to be
import let name
. Then you would have a clear distinction between what comes in, and what goes out.Contrived example.
form.svelte
field.svelte
How important is this feature to you?
It's not critical, but for the above example, it makes things very clear what comes in and out. If both variable declarations were export, which is currently required, it makes things a bit confusing and requires code comments to explain.
The text was updated successfully, but these errors were encountered: