-
-
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 store direct property assignment (#5416)
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
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
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
32 changes: 32 additions & 0 deletions
32
test/runtime/samples/store-assignment-updates-property/_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,32 @@ | ||
export default { | ||
html: ` | ||
<p>a: {"foo":3,"bar":2}</p> | ||
<p>b: {"foo":3}</p> | ||
<button></button> | ||
<button></button> | ||
`, | ||
skip_if_ssr: true, | ||
|
||
async test({ assert, component, target, window }) { | ||
const [btn1, btn2] = target.querySelectorAll('button'); | ||
const click = new window.MouseEvent('click'); | ||
|
||
await btn1.dispatchEvent(click); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<p>a: {"foo":4,"bar":2}</p> | ||
<p>b: {"foo":4,"baz":0}</p> | ||
<button></button> | ||
<button></button> | ||
`); | ||
|
||
await btn2.dispatchEvent(click); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<p>a: {"foo":5,"bar":2}</p> | ||
<p>b: {"foo":5,"qux":0}</p> | ||
<button></button> | ||
<button></button> | ||
`); | ||
} | ||
}; |
24 changes: 24 additions & 0 deletions
24
test/runtime/samples/store-assignment-updates-property/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> | ||
import { writable } from '../../../../store'; | ||
const a = writable({ foo: 1, bar: 2 }); | ||
$a.foo = 3; | ||
const b = writable({ foo: 1, bar: 2 }); | ||
$b = { foo: 3 }; | ||
function update() { | ||
$a.foo = $a.foo + 1; | ||
$b = { foo: $b.foo + 1, qux: 0 }; | ||
} | ||
</script> | ||
|
||
<p>a: {JSON.stringify($a)}</p> | ||
<p>b: {JSON.stringify($b)}</p> | ||
|
||
<button on:click={() => { | ||
$a.foo = $a.foo + 1; | ||
$b = { foo: $b.foo + 1, baz: 0 }; | ||
}} /> | ||
|
||
<button on:click={update} /> |