Skip to content

Feature Request: allow exporting rune from component as dynamic getters #16049

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

Open
mizulu opened this issue May 31, 2025 · 5 comments
Open

Feature Request: allow exporting rune from component as dynamic getters #16049

mizulu opened this issue May 31, 2025 · 5 comments
Milestone

Comments

@mizulu
Copy link

mizulu commented May 31, 2025

Describe the problem

currently

export function showModal(){}

compiles to

return $.pop({ showModal});

and exporting a rune or a variable is not allowed

export let someVar = 5
export let isOpen = $state()

Describe the proposed solution

This feature suggests exporting a binding to variables / runes using dynamic accessors

export let isOpen = $state();  // allow exporting runes 
export let someVar = 5;         // allow exporting variable binding 
export function showModal();

can be compiled to:

return $.pop({ showModal, get isOpen(){
  return $.get(isOpen)   // use the reactive accessor 
}, 
get someVar(){
  return someVar;  // return local variable
}});

Importance

would make my life easier

@Ocean-OS
Copy link
Contributor

Is there a reason props can't be used here?

@7nik
Copy link
Contributor

7nik commented May 31, 2025

It works:

let name = $state('world');

export { name };

@7nik
Copy link
Contributor

7nik commented May 31, 2025

For now, it will be too confusing with legacy/svelte4 prop declaration.
Exporting function is allowed because its semantics didn't change, but for exported variables it would mean that it defines component prop in legacy mode and component accessor in rune mode, which is confusing.

@Thiagolino8
Copy link

It will probably be allowed once legacy mode cease to exist #10523

@Rich-Harris Rich-Harris added this to the post-legacy milestone Jun 2, 2025
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

5 participants