fix: improve handling of object property deletions (#10456)

* fix: improve handling of object property deletions

* revert

* revert

* revert
pull/10458/head
Dominic Gannaway 11 months ago committed by GitHub
parent 1366932dc0
commit 9161448ee5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: improve handling of object property deletions

@ -157,7 +157,7 @@ const state_proxy_handler = {
}
if (s !== undefined) set(s, UNINITIALIZED);
if (prop in target) update(metadata.v);
if (boolean) update(metadata.v);
return boolean;
},

@ -0,0 +1,20 @@
import { test } from '../../test';
export default test({
html: '<button>set</button><button>delete</button><p>a,b,c</p><p>{"a":1,"b":2,"c":3}</p>',
async test({ assert, target }) {
const [btn, bt2] = target.querySelectorAll('button');
await btn?.click();
assert.htmlEqual(
target.innerHTML,
`<button>set</button><button>delete</button><p>a,b,c</p><p>{"a":1,"b":2,"c":3}</p>`
);
await bt2?.click();
assert.htmlEqual(
target.innerHTML,
`<button>set</button><button>delete</button><p>a,c</p><p>{"a":1,"c":3}</p>`
);
}
});

@ -0,0 +1,8 @@
<script>
let numbers = $state({ a: 1, b: 2, c: 3 });
</script>
<button onclick={() => { numbers.b = 2; }}>set</button>
<button onclick={() => { delete numbers.b; }}>delete</button>
<p>{Object.keys(numbers)}</p>
<p>{JSON.stringify(numbers)}</p>
Loading…
Cancel
Save