-
-
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
Bring back $state.is
rune
#13582
Comments
|
Svelte would probably need to track object-proxy associations in an internal |
If it's not too much to ask, kindly ELI5 the whys and hows of "mutating the original object" affects this issue or separate tracking is needed (for my edification). I don't have enough context to know why might simply exporting
|
So when you pass the object to |
Convince me more: |
If you read the field then it becomes a new object. Proxying deep is lazily done, not eagerly, so if you read it then it will change identity and thus goes back to my above points. |
Okay. Convinced and edified. |
I discovered the |
This is about like each blocks – in where we needs keys to understand identity. If you can make your objects use an id or some form of key then you can easily compare identity in both places. Unfortunately, proxies can be a misleading, which is why we changed our approach from before to ensure that we didn't mutate the underlying object when you mutate the proxied object – as this was causing very unfortunate side-effects that were almost impossible to debug. I don't think there's a silver bullet or an additional API here that can make this problem go away. If you have any ideas, please let us know, but |
Hmm. I'm writing a library where I receive arrays with unknown/arbitrary elements passed down a hierarchy much like the I think rather than accept |
That's a good approach. Closing this now as nothing is actionable :) |
Describe the problem
The
$state.is()
rune was removed with the argument that$state.raw
makes it not needed. In #12916 (comment) Rich says:item[0]
being passed toListItem
and thencreateListItem()
where I want to doconst active = $derived(myRootComponent.value === item)
and return{ get foo() { return item.deep.value.foo; }
$state
only for you to later realize you need to compare it with something downstream.items[0]
to be a reactive signal/proxy...but also compare it withselected
.Expecting someone to just "Write your code in such a way that you don't need to compare a proxy with a non-proxy" is not a reasonable request because:
a) It needs engineering time to refactor the entire state & component tree that touches a piece of data potentially proxying it while
$state.is
would otherwise suffice.b) There's no easy way to enforce that distant up-stream or down-stream consumers not to proxy data.
c) I now need to document and recall arguments/props that should not be deep proxies as I'm passing them to places that do comparison...and I need to actually know if they do comparison
d) Probably most importantly, my data is already proxied, I want it to be deeply reactive, but I also want to compare it. What can we do about it?
Describe the proposed solution
Bring
$state.is
back. Alternatively, some other solution that allows dealing with proxied data after the fact and preserves object identity (e.g$state.unproxify
) is also welcome.Importance
i cannot use svelte without it
The text was updated successfully, but these errors were encountered: