Skip to content
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

Reactive statement two way binding bug #5995

Closed
NikolayMakhonin opened this issue Feb 16, 2021 · 1 comment
Closed

Reactive statement two way binding bug #5995

NikolayMakhonin opened this issue Feb 16, 2021 · 1 comment

Comments

@NikolayMakhonin
Copy link

see this repl

<script>
	let obj = {};
	function objToState() {
		console.log('objToState')
		state.bool = obj.bool
	}

	let state = {};
	function stateToObj() {
		console.log('stateToObj')
		obj.bool = state.bool
	}
	
	$: obj && objToState()
	$: state && stateToObj()
	// $: obj && objToState()
</script>

<input type="checkbox" bind:checked="{state.bool}" /><br>
<input type="checkbox" bind:checked="{obj.bool}" /><br>

If I click the stateToObj checkbox, I see this in the console:

"stateToObj"
"objToState"

It is correct

But if I click the stateToObj checkbox, I see only this:

"objToState"

It is incorrect, I expect to see the same log

It turns out that in order to implement two way binding of obj with state, I need to add another line (which is now commented)

Information about your Svelte project:

  • Your browser and the version: Chrome 88

  • Your operating system: Windows 7

  • Svelte version: 3.32.3

@Conduitry
Copy link
Member

This is intended behavior. See my explanation in #5848.

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

2 participants