-
-
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
Unexpected reactivity #3065
Comments
It's because svelte reacts when you reassign (example: array = array[..array, value]), not when you update the value (example: array.push(value)). |
Self-assignment is a documented workaround to force Svelte to update mutable objects. You can use |
But why reacts if is the same value (pointer to that array)? And why reacts to the same value only to arrays and not other value types? |
Ok, so that tag is the solution for the select. But why it reacts if I don't touch the array when i select an item? |
Svelte doesn't store and compare the value. When you write this: let value = "something";
value = "foo"; The svelte compiler turns it into something like this: let value = "something";
value = "foo"; $$invalidate("value"); $$invalidate() basically tells svelte that the variabler was reassigned.
The type does not matter. |
Ok, objects behave the same. But strings, numbers, bools why don't react if
I reassign with the same value?
…On Fri, 21 Jun 2019, 16:49 Ax333l, ***@***.***> wrote:
But why reacts if is the same value (pointer to that array)?
Svelte doesn't store and compare the value. When you write this:
let value = "something";
value = "foo";
The svelte compiler turns it into something like this:
let value = "something";
value = "foo"; $$invalidate("value");
$$invalidate() basically tells svelte that the variabler was reassigned.
And why reacts to the same value only to arrays and not other value types?
The type does not matter.
I could make an example with objects but I an on my phone right now :/
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3065?email_source=notifications&email_token=AI25BMSCOZBPHRH63WOWSQDP3TL6JA5CNFSM4H2NRH5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYIQOGQ#issuecomment-504432410>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AI25BMS36SEMVSZWM2KW7FLP3TL6JANCNFSM4H2NRH5A>
.
|
Checkout the source code for |
View in REPL
The text was updated successfully, but these errors were encountered: