mirror of https://github.com/sveltejs/svelte
parent
803ebd5676
commit
50e41c23be
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ensure assignments to state field inside constructor trigger effects
|
@ -0,0 +1,20 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>10</button>`,
|
||||
|
||||
test({ assert, target, logs }) {
|
||||
const btn = target.querySelector('button');
|
||||
|
||||
btn?.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(target.innerHTML, `<button>11</button>`);
|
||||
|
||||
btn?.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(target.innerHTML, `<button>12</button>`);
|
||||
|
||||
assert.deepEqual(logs, [0, 10, 11, 12]);
|
||||
}
|
||||
});
|
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
class Counter {
|
||||
count = $state(0);
|
||||
|
||||
constructor(initial) {
|
||||
$effect.pre(() => {
|
||||
console.log(this.count);
|
||||
});
|
||||
|
||||
this.count = initial;
|
||||
}
|
||||
}
|
||||
|
||||
const counter = new Counter(10);
|
||||
</script>
|
||||
|
||||
<button onclick={() => counter.count++}>{counter.count}</button>
|
@ -1,3 +0,0 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({});
|
@ -1,27 +0,0 @@
|
||||
import "svelte/internal/disclose-version";
|
||||
import * as $ from "svelte/internal/client";
|
||||
|
||||
export default function Class_state_field_constructor_assignment($$anchor, $$props) {
|
||||
$.push($$props, true);
|
||||
|
||||
class Foo {
|
||||
#a = $.source();
|
||||
|
||||
get a() {
|
||||
return $.get(this.#a);
|
||||
}
|
||||
|
||||
set a(value) {
|
||||
$.set(this.#a, $.proxy(value));
|
||||
}
|
||||
|
||||
#b = $.source();
|
||||
|
||||
constructor() {
|
||||
this.#a.v = 1;
|
||||
this.#b.v = 2;
|
||||
}
|
||||
}
|
||||
|
||||
$.pop();
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
import * as $ from "svelte/internal/server";
|
||||
|
||||
export default function Class_state_field_constructor_assignment($$payload, $$props) {
|
||||
$.push();
|
||||
|
||||
class Foo {
|
||||
a;
|
||||
#b;
|
||||
|
||||
constructor() {
|
||||
this.a = 1;
|
||||
this.#b = 2;
|
||||
}
|
||||
}
|
||||
|
||||
$.pop();
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<script>
|
||||
class Foo {
|
||||
a = $state();
|
||||
#b = $state();
|
||||
|
||||
constructor() {
|
||||
this.a = 1;
|
||||
this.#b = 2;
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Reference in new issue