Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow state and derived declarations inside class constructors
- Loading branch information
1 parent
f2f71ae
commit d45c8f0
Showing
8 changed files
with
211 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"svelte": patch | ||
--- | ||
|
||
feat: allow state and derived declarations inside class constructors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/svelte/tests/runtime-runes/samples/class-state-in-constructor/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
solo: true, | ||
html: ` | ||
<button>0</button> | ||
<button>0</button> | ||
`, | ||
|
||
async test({ assert, target }) { | ||
const [btn1, btn2] = target.querySelectorAll('button'); | ||
|
||
await btn1?.click(); | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>1</button> | ||
<button>0</button> | ||
` | ||
); | ||
|
||
await btn2?.click(); | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>2</button> | ||
<button>1</button> | ||
` | ||
); | ||
} | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/svelte/tests/runtime-runes/samples/class-state-in-constructor/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script> | ||
class Counter { | ||
#count; | ||
get secretCount() { | ||
return this.#count; | ||
} | ||
constructor() { | ||
this.#count = $state(0); // TODO | ||
this.count = $state(0); | ||
this.double = $derived(this.count * 2); | ||
} | ||
increment() { | ||
this.#count++; | ||
this.count++; | ||
} | ||
} | ||
const counter = new Counter(); | ||
</script> | ||
|
||
<button on:click={() => counter.count++}>{counter.count}</button> | ||
<button on:click={counter.increment}>{counter.secretCount}</button> |