mirror of https://github.com/sveltejs/svelte
fix: keep default values of props a proxy after reassignment (#11860)
* fix: keep default values of props a proxy after reassignment * fix: make this work for non bindable props too * chore: more comprehensive test * chore: cast away * chore: better variable name and check * chore: fix lintpull/11889/head
parent
0a7de87eb5
commit
5eb8641ac7
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: keep default values of props a proxy after reassignment
|
@ -1,12 +1,20 @@
|
||||
<script>
|
||||
/** @type {{ object?: { count: number }}} */
|
||||
let { object = $bindable({ count: 0 }) } = $props();
|
||||
/** @type {{ object?: { count: number }, non_bindable?: { count: number }}} */
|
||||
let { object = $bindable({ count: 0 }), non_bindable = { count: 0 } } = $props();
|
||||
</script>
|
||||
|
||||
<button onclick={() => object.count += 1}>
|
||||
<button onclick={() => (object.count += 1)}>
|
||||
mutate: {object.count}
|
||||
</button>
|
||||
|
||||
<button onclick={() => object = { count: object.count + 1 } }>
|
||||
<button onclick={() => (object = { count: object.count + 1 })}>
|
||||
reassign: {object.count}
|
||||
</button>
|
||||
|
||||
<button onclick={() => (non_bindable.count += 1)}>
|
||||
mutate: {non_bindable.count}
|
||||
</button>
|
||||
|
||||
<button onclick={() => (non_bindable = { count: non_bindable.count + 1 })}>
|
||||
reassign: {non_bindable.count}
|
||||
</button>
|
||||
|
Loading…
Reference in new issue