-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
extract onchange
callbacks from options
#15579
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
Conversation
|
|
I like the syntax more but I'm a bit scared because this will lock us into not adding any new option before svelte 6 unless we go the $state(0, ()=>{}, {...}); Or with variadic arguments. That said I agree is probably unlikely we would need to add any new option (I can't think of anything) and we could always resort to a new rune. |
In this pr the second argument should be a function |
Oh wait I'm super wrong and I completely misunderstood the PR 😑 I shouldn't check those on the phone lol |
Huh, I'm amazed we currently allow spread arguments to |
But yeah I think this basically forces the argument to be statically analyzable to pass the function which we decided against no? |
I think there's a meaningful distinction between allowing spread elements (which no-one would ever need) and allowing arbitrary expressions for the second argument (which is potentially useful) |
Yeah I think we can just disallow spread |
Would that be considered a breaking tho? I don't think no one in their right mind ever did this but... 😁 |
I think that should be a breaking change just in case. |
The alternative is to unwrap the rest $.state(args[0], args[1].onchange); |
I mean we could do that but if someone has actually written that code then god help them. I don't think this rises to the level of 'breaking change' |
I have the change locally...should i push it? |
i pushed it...we can always revert if we don't want it |
I think it adds a lot of needless complexity, I'd much rather we just prohibit spread arguments with runes (except perhaps |
I mean...i think we are safe 😄😄😄 |
Opened a PR to prevent spreads |
Hi, My two cents : I think that the compiler should throw an error when options contains incorrect properties : let name = $state('world', {
xxx: 42 // should throw "Invalid option for $state()"
}); |
We removed a bunch of this compiler errors deferring the work to typescript |
Since we're now disallowing spreads I'll go ahead and merge this |
This is a PR against #15069. My thesis is that it's quite unlikely we'll end up with more state options, and until we do we can make things more efficient by just passing the callbacks around rather than creating a bunch of objects and cloning them
cc @paoloricciuti