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

Add setter to let variables accessors #11983

Closed
Thiagolino8 opened this issue Jun 10, 2024 · 4 comments · Fixed by #12345
Closed

Add setter to let variables accessors #11983

Thiagolino8 opened this issue Jun 10, 2024 · 4 comments · Fixed by #12345
Milestone

Comments

@Thiagolino8
Copy link

Thiagolino8 commented Jun 10, 2024

Describe the problem

In Svelte 3/4 the export keyword created accessors for const variables and functions and created props for let variables and when using the accessors option the keyword also created accessors for let variables
In Svelte 5, the export keyword only creates accessors, but unlike v4 accessors, v5 accessors only have read capacity, creating a feature disparity between versions

Describe the proposed solution

Add setters to accessors of variables declared using let exported from a component

Importance

would make my life easier

@brunnerh
Copy link
Member

brunnerh commented Jun 10, 2024

Exporting a let variable in v4 is a property.
The equivalent in v5 should not be an export but a $props() declaration.

(There also is a compiler option legacy.componentsApi which might have an effect on the behavior - see these docs. At the very least you would be able to use $set on the component.)

@7nik
Copy link

7nik commented Jun 10, 2024

You still can export function-setters

export const setMyProp = (v) => { myProp = v; };

or an object with all [writable] props

export const options1 = someStateObject;
export const options2 = {
  get myProp() { return myProp; },
  set myProp(v) { myProp = v; },
};

@Rich-Harris Rich-Harris added this to the 5.0 milestone Jun 10, 2024
@Rich-Harris
Copy link
Member

This was a deliberate choice though I can't exactly remember the rationale. Adding the 5.0 milestone so that we reach a final decision on this before the semver window closes

@dummdidumm
Copy link
Member

dummdidumm commented Jul 8, 2024

This was originally requested in #10310 (the readonly version) and then implemented in #10523 but without any real rationale for one way or the other. The only one I could imagine is "it makes the difference between export { x } in regular modules and component instances even more drastic".

I would be ok with adjusting that so that $state exports are settable.

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

Successfully merging a pull request may close this issue.

5 participants