-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: consider variables with synthetic store sub as state (#14195)
Fixes #14183
- Loading branch information
1 parent
1eed645
commit ea0d80e
Showing
5 changed files
with
65 additions
and
0 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 | ||
--- | ||
|
||
fix: consider variables with synthetic store sub as state |
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
11 changes: 11 additions & 0 deletions
11
packages/svelte/tests/runtime-legacy/samples/variable-assigned-store-state/Test.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,11 @@ | ||
<script> | ||
export let store; | ||
let currentStore; | ||
function update(){ | ||
currentStore = store | ||
} | ||
</script> | ||
|
||
<button on:click={update}></button> | ||
<p>{$currentStore}</p> |
29 changes: 29 additions & 0 deletions
29
packages/svelte/tests/runtime-legacy/samples/variable-assigned-store-state/_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,29 @@ | ||
import { flushSync } from 'svelte'; | ||
import { ok, test } from '../../test'; | ||
|
||
export default test({ | ||
async test({ assert, target, window }) { | ||
const [btn1, btn2] = target.querySelectorAll('button'); | ||
const p = target.querySelector('p'); | ||
|
||
assert.equal(p?.innerHTML, ''); | ||
|
||
flushSync(() => { | ||
btn2.click(); | ||
}); | ||
|
||
assert.equal(p?.innerHTML, '1'); | ||
|
||
flushSync(() => { | ||
btn1.click(); | ||
}); | ||
|
||
assert.equal(p?.innerHTML, '1'); | ||
|
||
flushSync(() => { | ||
btn2.click(); | ||
}); | ||
|
||
assert.equal(p?.innerHTML, '2'); | ||
} | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/runtime-legacy/samples/variable-assigned-store-state/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,9 @@ | ||
<script> | ||
import { writable } from 'svelte/store' | ||
import Test from './Test.svelte' | ||
let counter = 1 | ||
let store = writable(counter) | ||
</script> | ||
|
||
<button on:click={() => store = writable(++counter)}></button> | ||
<Test {store} /> |