call attr bindings if tag is custom element

pull/7766/head
Yuichiro Yamashita 4 years ago
parent 8513e299ef
commit 9ed5cc1782

@ -803,15 +803,31 @@ export default class ElementWrapper extends Wrapper {
const fn = this.node.namespace === namespaces.svg ? x`@set_svg_attributes` : x`@set_attributes`; const fn = this.node.namespace === namespaces.svg ? x`@set_svg_attributes` : x`@set_attributes`;
block.chunks.hydrate.push( if (this.node.is_dynamic_element) {
b`${fn}(${this.var}, ${data});` // call attribute bindings for custom element if tag is custom element
); const tag = this.node.tag_expr.manipulate(block);
const attr_update = b`
if (/-/.test(${tag})) {
@set_custom_element_data_map(${this.var}, ${data});
} else {
${fn}(${this.var}, ${data});
}`;
block.chunks.hydrate.push(attr_update);
block.chunks.update.push(b`
${data} = @get_spread_update(${levels}, [${updates}]);
${attr_update}`
);
} else {
block.chunks.hydrate.push(
b`${fn}(${this.var}, ${data});`
);
block.chunks.update.push(b` block.chunks.update.push(b`
${fn}(${this.var}, ${data} = @get_spread_update(${levels}, [ ${fn}(${this.var}, ${data} = @get_spread_update(${levels}, [
${updates} ${updates}
])); ]));
`); `);
}
// handle edge cases for elements // handle edge cases for elements
if (this.node.name === 'select') { if (this.node.name === 'select') {

@ -310,6 +310,12 @@ export function set_svg_attributes(node: Element & ElementCSSInlineStyle, attrib
} }
} }
export function set_custom_element_data_map(node, data_map: Record<string, unknown>) {
Object.keys(data_map).forEach((key) => {
set_custom_element_data(node, key, data_map[key]);
});
}
export function set_custom_element_data(node, prop, value) { export function set_custom_element_data(node, prop, value) {
if (prop in node) { if (prop in node) {
node[prop] = typeof node[prop] === 'boolean' && value === '' ? true : value; node[prop] = typeof node[prop] === 'boolean' && value === '' ? true : value;

Loading…
Cancel
Save