@ -174,6 +174,8 @@ export default class ElementWrapper extends Wrapper {
child_dynamic_element_block? : Block = null ;
child_dynamic_element? : ElementWrapper = null ;
element_data_name = null ;
constructor (
renderer : Renderer ,
block : Block ,
@ -287,6 +289,8 @@ export default class ElementWrapper extends Wrapper {
}
this . fragment = new FragmentWrapper ( renderer , block , node . children , this , strip_whitespace , next_sibling ) ;
this . element_data_name = block . get_unique_name ( ` ${ this . var . name } _data ` ) ;
}
render ( block : Block , parent_node : Identifier , parent_nodes : Identifier ) {
@ -516,7 +520,8 @@ export default class ElementWrapper extends Wrapper {
child . render (
block ,
is_template ? x ` ${ node } .content ` : node ,
nodes
nodes ,
{ element_data_name : this.element_data_name }
) ;
} ) ;
}
@ -824,7 +829,6 @@ export default class ElementWrapper extends Wrapper {
add_spread_attributes ( block : Block ) {
const levels = block . get_unique_name ( ` ${ this . var . name } _levels ` ) ;
const data = block . get_unique_name ( ` ${ this . var . name } _data ` ) ;
const initial_props = [ ] ;
const updates = [ ] ;
@ -855,9 +859,9 @@ export default class ElementWrapper extends Wrapper {
block . chunks . init . push ( b `
let $ { levels } = [ $ { initial_props } ] ;
let $ { data} = { } ;
let $ { this . element_ data_name } = { } ;
for ( let # i = 0 ; # i < $ { levels } . length ; # i += 1 ) {
$ { data} = @assign ( $ { data} , $ { levels } [ # i ] ) ;
$ { this . element_ data_name } = @assign ( $ { this . element_ data_name } , $ { levels } [ # i ] ) ;
}
` );
@ -869,12 +873,12 @@ export default class ElementWrapper extends Wrapper {
: x ` @set_attributes ` ;
block . chunks . hydrate . push (
b ` ${ fn } ( ${ this . var } , ${ data} ); `
b ` ${ fn } ( ${ this . var } , ${ this . element_ data_name } ); `
) ;
if ( this . has_dynamic_attribute ) {
block . chunks . update . push ( b `
$ { fn } ( $ { this . var } , $ { data} = @get_spread_update ( $ { levels } , [
$ { fn } ( $ { this . var } , $ { this . element_ data_name } = @get_spread_update ( $ { levels } , [
$ { updates }
] ) ) ;
` );
@ -890,23 +894,23 @@ export default class ElementWrapper extends Wrapper {
}
block . chunks . mount . push ( b `
'value' in $ { data} && ( $ { data} . multiple ? @select_options : @select_option ) ( $ { this . var } , $ { data} . value ) ;
'value' in $ { this . element_ data_name } && ( $ { this . element_ data_name } . multiple ? @select_options : @select_option ) ( $ { this . var } , $ { this . element_ data_name } . value ) ;
` );
block . chunks . update . push ( b `
if ( $ { block . renderer . dirty ( Array . from ( dependencies ) ) } && 'value' in $ { data} ) ( $ { data} . multiple ? @select_options : @select_option ) ( $ { this . var } , $ { data} . value ) ;
if ( $ { block . renderer . dirty ( Array . from ( dependencies ) ) } && 'value' in $ { this . element_ data_name } ) ( $ { this . element_ data_name } . multiple ? @select_options : @select_option ) ( $ { this . var } , $ { this . element_ data_name } . value ) ;
` );
} else if ( this . node . name === 'input' && this . attributes . find ( attr = > attr . node . name === 'value' ) ) {
const type = this . node . get_static_attribute_value ( 'type' ) ;
if ( type === null || type === '' || type === 'text' || type === 'email' || type === 'password' ) {
block . chunks . mount . push ( b `
if ( 'value' in $ { data} ) {
$ { this . var } . value = $ { data} . value ;
if ( 'value' in $ { this . element_ data_name } ) {
$ { this . var } . value = $ { this . element_ data_name } . value ;
}
` );
block . chunks . update . push ( b `
if ( 'value' in $ { data} ) {
$ { this . var } . value = $ { data} . value ;
if ( 'value' in $ { this . element_ data_name } ) {
$ { this . var } . value = $ { this . element_ data_name } . value ;
}
` );
}
@ -1232,7 +1236,6 @@ export default class ElementWrapper extends Wrapper {
}
` );
}
} ) ;
}