-
-
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 assigning item in each not reactive
- Loading branch information
Showing
6 changed files
with
181 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
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,14 @@ | ||
import { Node } from 'estree'; | ||
|
||
export default function replace_object(node: Node, replacement: Node) { | ||
if (node.type === 'Identifier') return replacement; | ||
|
||
const ancestor = node; | ||
let parent; | ||
while (node.type === 'MemberExpression') { | ||
parent = node; | ||
node = node.object; | ||
} | ||
parent.object = replacement; | ||
return ancestor; | ||
} |
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,20 @@ | ||
export default { | ||
html: ` | ||
<span class="content">foo</span> | ||
<button>Test</button> | ||
`, | ||
async test({ assert, component, target, window }) { | ||
const button = target.querySelector("button"); | ||
|
||
const clickEvent = new window.MouseEvent("click"); | ||
await button.dispatchEvent(clickEvent); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<span class="content">bar</span> | ||
<button>Test</button> | ||
` | ||
); | ||
}, | ||
}; |
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,12 @@ | ||
<script> | ||
let obj = { | ||
prop: "foo" | ||
}; | ||
let arr = [obj] | ||
</script> | ||
|
||
{#each arr as o} | ||
<span class="content">{o.prop}</span> | ||
<button on:click={ () => o = { ...o, prop: "bar" } }>Test</button> | ||
{/each} |
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,97 @@ | ||
export default { | ||
html: ` | ||
<button>Add</button> | ||
<span class="content">1</span> | ||
<button>Test</button> | ||
<span class="content">2</span> | ||
<button>Test</button> | ||
<span class="content">3</span> | ||
<button>Test</button> | ||
`, | ||
async test({ assert, component, target, window }) { | ||
let [incrementBtn, ...buttons] = target.querySelectorAll("button"); | ||
|
||
const clickEvent = new window.MouseEvent("click"); | ||
await buttons[0].dispatchEvent(clickEvent); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>Add</button> | ||
<span class="content">2</span> | ||
<button>Test</button> | ||
<span class="content">2</span> | ||
<button>Test</button> | ||
<span class="content">3</span> | ||
<button>Test</button> | ||
` | ||
); | ||
|
||
await buttons[0].dispatchEvent(clickEvent); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>Add</button> | ||
<span class="content">4</span> | ||
<button>Test</button> | ||
<span class="content">2</span> | ||
<button>Test</button> | ||
<span class="content">3</span> | ||
<button>Test</button> | ||
` | ||
); | ||
|
||
await buttons[2].dispatchEvent(clickEvent); | ||
await buttons[2].dispatchEvent(clickEvent); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>Add</button> | ||
<span class="content">4</span> | ||
<button>Test</button> | ||
<span class="content">2</span> | ||
<button>Test</button> | ||
<span class="content">12</span> | ||
<button>Test</button> | ||
` | ||
); | ||
|
||
await incrementBtn.dispatchEvent(clickEvent); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>Add</button> | ||
<span class="content">4</span> | ||
<button>Test</button> | ||
<span class="content">2</span> | ||
<button>Test</button> | ||
<span class="content">12</span> | ||
<button>Test</button> | ||
<span class="content">4</span> | ||
<button>Test</button> | ||
` | ||
); | ||
|
||
[incrementBtn, ...buttons] = target.querySelectorAll("button"); | ||
|
||
await buttons[3].dispatchEvent(clickEvent); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>Add</button> | ||
<span class="content">4</span> | ||
<button>Test</button> | ||
<span class="content">2</span> | ||
<button>Test</button> | ||
<span class="content">12</span> | ||
<button>Test</button> | ||
<span class="content">8</span> | ||
<button>Test</button> | ||
` | ||
); | ||
}, | ||
}; |
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,13 @@ | ||
<script> | ||
let obj = { | ||
prop: "foo" | ||
}; | ||
let arr = [1, 2, 3] | ||
</script> | ||
|
||
<button on:click={() => arr = [...arr, arr.length + 1]}>Add</button> | ||
{#each arr as o} | ||
<span class="content">{o}</span> | ||
<button on:click={() => { o *= 2; }}>Test</button> | ||
{/each} |