File tree Expand file tree Collapse file tree 5 files changed +40
-21
lines changed
src/compiler/compile/render_dom
test/runtime/samples/store-each-binding-deep Expand file tree Collapse file tree 5 files changed +40
-21
lines changed Original file line number Diff line number Diff line change 1010* Fix using ` <Namespaced.Component/> ` s in child ` {#await} ` /` {#each} ` contexts ([ #5255 ] ( https://github.com/sveltejs/svelte/issues/5255 ) )
1111* Fix using ` <svelte:component> ` in ` {:catch} ` ([ #5259 ] ( https://github.com/sveltejs/svelte/issues/5259 ) )
1212* Fix setting one-way bound ` <input> ` ` value ` to ` undefined ` when it has spread attributes ([ #5270 ] ( https://github.com/sveltejs/svelte/issues/5270 ) )
13+ * Fix deep two-way bindings inside an ` {#each} ` involving a store ([ #5286 ] ( https://github.com/sveltejs/svelte/issues/5286 ) )
1314
1415## 3.24.1
1516
Original file line number Diff line number Diff line change @@ -4,21 +4,23 @@ import { b, x } from 'code-red';
44import { Node , Identifier , ArrayPattern } from 'estree' ;
55import { is_head } from './wrappers/shared/is_head' ;
66
7+ export interface Bindings {
8+ object : Identifier ;
9+ property : Identifier ;
10+ snippet : Node ;
11+ store : string ;
12+ tail : Node ;
13+ modifier : ( node : Node ) => Node ;
14+ }
15+
716export interface BlockOptions {
817 parent ?: Block ;
918 name : Identifier ;
1019 type : string ;
1120 renderer ?: Renderer ;
1221 comment ?: string ;
1322 key ?: Identifier ;
14- bindings ?: Map < string , {
15- object : Identifier ;
16- property : Identifier ;
17- snippet : Node ;
18- store : string ;
19- tail : Node ;
20- modifier : ( node : Node ) => Node ;
21- } > ;
23+ bindings ?: Map < string , Bindings > ;
2224 dependencies ?: Set < string > ;
2325}
2426
@@ -36,14 +38,7 @@ export default class Block {
3638
3739 dependencies : Set < string > = new Set ( ) ;
3840
39- bindings : Map < string , {
40- object : Identifier ;
41- property : Identifier ;
42- snippet : Node ;
43- store : string ;
44- tail : Node ;
45- modifier : ( node : Node ) => Node ;
46- } > ;
41+ bindings : Map < string , Bindings > ;
4742
4843 chunks : {
4944 declarations : Array < Node | Node [ ] > ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import FragmentWrapper from './Fragment';
77import { b , x } from 'code-red' ;
88import ElseBlock from '../../nodes/ElseBlock' ;
99import { Identifier , Node } from 'estree' ;
10+ import get_object from '../../utils/get_object' ;
1011
1112export class ElseBlockWrapper extends Wrapper {
1213 node : ElseBlock ;
@@ -139,11 +140,8 @@ export default class EachBlockWrapper extends Wrapper {
139140 view_length : fixed_length === null ? x `${ iterations } .length` : fixed_length
140141 } ;
141142
142- const store =
143- node . expression . node . type === 'Identifier' &&
144- node . expression . node . name [ 0 ] === '$'
145- ? node . expression . node . name . slice ( 1 )
146- : null ;
143+ const object = get_object ( node . expression . node ) ;
144+ const store = object . type === 'Identifier' && object . name [ 0 ] === '$' ? object . name . slice ( 1 ) : null ;
147145
148146 node . contexts . forEach ( prop => {
149147 this . block . bindings . set ( prop . key . name , {
Original file line number Diff line number Diff line change 1+ export default {
2+ async test ( { assert, target, window } ) {
3+ const input = target . querySelector ( 'input' ) ;
4+
5+ const event = new window . Event ( 'input' ) ;
6+ input . value = 'changed' ;
7+ await input . dispatchEvent ( event ) ;
8+
9+ assert . htmlEqual ( target . innerHTML , `
10+ <input>
11+ <p>changed</p>
12+ ` ) ;
13+ }
14+ } ;
Original file line number Diff line number Diff line change 1+ <script >
2+ import { writable } from ' svelte/store' ;
3+
4+ let itemStore = writable ({prop: {things: [{name: " item store" }]}});
5+ </script >
6+
7+ {#each $itemStore .prop .things as thing }
8+ <input bind:value ={thing .name } >
9+ {/each }
10+
11+ <p >{$itemStore .prop .things [0 ].name }</p >
You can’t perform that action at this time.
0 commit comments