mirror of https://github.com/sveltejs/svelte
fix: increment private state fields through a non-`this` receiver (#18622)
parent
20b341f100
commit
135f4439c3
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: increment private state fields through a non-`this` receiver
|
||||
@ -0,0 +1,22 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>1</button><button>drop</button>`,
|
||||
|
||||
test({ assert, target }) {
|
||||
const [bump, drop] = target.querySelectorAll('button');
|
||||
|
||||
bump?.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(target.innerHTML, `<button>2</button><button>drop</button>`);
|
||||
|
||||
bump?.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(target.innerHTML, `<button>3</button><button>drop</button>`);
|
||||
|
||||
drop?.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(target.innerHTML, `<button>2</button><button>drop</button>`);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,23 @@
|
||||
<script>
|
||||
class Counter {
|
||||
#count = $state(1);
|
||||
|
||||
bump(other) {
|
||||
other.#count++;
|
||||
}
|
||||
|
||||
drop(other) {
|
||||
--other.#count;
|
||||
}
|
||||
|
||||
getCount() {
|
||||
return this.#count;
|
||||
}
|
||||
}
|
||||
|
||||
const a = new Counter();
|
||||
const b = new Counter();
|
||||
</script>
|
||||
|
||||
<button onclick={() => a.bump(b)}>{b.getCount()}</button>
|
||||
<button onclick={() => a.drop(b)}>drop</button>
|
||||
Loading…
Reference in new issue