-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
feat: add $state.is rune #11613
feat: add $state.is rune #11613
Conversation
🦋 Changeset detectedLatest commit: c915f59 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
For arrays, isn't let item = $state(maybeRawItem);
let index = array.indexOf(item); better than let index = array.findIndex((item) => $state.is(item, maybeRawItem)); ? |
How do you mean? The first example won’t work? |
The first example is better for performance, but not mentioning it may force people to use the second approach. |
They should use the second approach here though? |
I doubt that many people are aware of let foo = {};
$state(foo) == $state(foo); // true and even may think the opposite and thus assume |
That’s what #11610 addresses |
So, if somebody carefully reads the docs and writes |
No, because that's invalid usage of the |
I don’t understand. Then this should not work as expected ? class MyClass {}
let a = new MyClass()
let b = new MyClass()
let c = $state([a, b])
console.log(c[0] === a) // log 'true' as expected But it works (REPL). Not sure to get the point where $state.is() is usefull then. |
Only POJOs are proxied. Class instances aren't. |
This PR adds the
$state.is
rune. Fixes #11403.Sometimes you might need to deal with the equality of two values, where one of the objects might have been wrapped in a with a
$state
proxy,you can use
$state.is
to check if the two values are the same.This is handy when you might want to check if the object exists within a deeply reactive object/array.