-
-
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] binding member expression should only invalidate the object, no…
…t the member property (#7008)
- Loading branch information
Showing
9 changed files
with
95 additions
and
2 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
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
18 changes: 18 additions & 0 deletions
18
test/runtime/samples/binding-input-member-expression-update/_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,18 @@ | ||
// binding member expression shouldn't invalidate the property name | ||
export default { | ||
async test({ assert, component, target, window }) { | ||
const input = target.querySelector('input'); | ||
assert.deepEqual(component.logs.length, 1); | ||
assert.equal(input.value, 'abc'); | ||
|
||
input.value = 'hij'; | ||
await input.dispatchEvent(new window.Event('input')); | ||
|
||
assert.deepEqual(component.values.a, 'hij'); | ||
assert.deepEqual(component.logs.length, 1); | ||
|
||
component.paths = ['b']; | ||
assert.deepEqual(component.logs.length, 2); | ||
assert.equal(input.value, 'def'); | ||
} | ||
}; |
9 changes: 9 additions & 0 deletions
9
test/runtime/samples/binding-input-member-expression-update/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> | ||
export let values = { a: 'abc', b: 'def' }; | ||
export let paths = ['a']; | ||
export let logs = []; | ||
$: paths && logs.push('paths updated'); | ||
</script> | ||
|
||
<input bind:value={values[paths[0]]} /> |
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,10 @@ | ||
export default { | ||
html: '<div>content</div><div>content</div><div>content</div>', | ||
|
||
test({ assert, target, component }) { | ||
const divs = target.querySelectorAll('div'); | ||
assert.equal(component.refs[0], divs[0]); | ||
assert.equal(component.refs[1], divs[1]); | ||
assert.equal(component.refs[2], divs[2]); | ||
} | ||
}; |
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,15 @@ | ||
<script> | ||
export let data = [ { id: '1' }, { id: '2' }, { id: '3' } ]; | ||
export let refs = []; | ||
// note that this is NOT data.slice().reverse() | ||
// as that wouldn't have triggered an infinite loop | ||
$: list = data.reverse(); | ||
</script> | ||
|
||
{#each list as { id }, index (id)} | ||
<div bind:this={refs[index]}> | ||
content | ||
</div> | ||
{/each} |
8 changes: 8 additions & 0 deletions
8
test/runtime/samples/binding-this-member-expression-update/_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,8 @@ | ||
// binding member expression shouldn't invalidate the property name | ||
export default { | ||
test({ assert, component, target }) { | ||
const div = target.querySelector('div'); | ||
assert.equal(div, component.container.a); | ||
assert.deepEqual(component.logs.length, 1); | ||
} | ||
}; |
9 changes: 9 additions & 0 deletions
9
test/runtime/samples/binding-this-member-expression-update/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> | ||
export let container = {}; | ||
export let paths = ['a']; | ||
export let logs = []; | ||
$: paths && logs.push('paths updated'); | ||
</script> | ||
|
||
<div bind:this={container[paths[0]]} /> |