get rid of spread_dynamic_element_attributes_effect

pull/10922/head
Rich Harris 2 years ago
parent 0f56430711
commit bfd95701cd

@ -343,6 +343,8 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
return false; return false;
} }
// TODO why are we always treating this as a spread? needs docs, if that's not an error
let needs_isolation = false; let needs_isolation = false;
let is_reactive = false; let is_reactive = false;
@ -365,23 +367,11 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
attribute.type === 'SpreadAttribute' && attribute.metadata.contains_call_expression; attribute.type === 'SpreadAttribute' && attribute.metadata.contains_call_expression;
} }
const isolated = b.stmt( if (needs_isolation || is_reactive) {
b.call(
'$.spread_dynamic_element_attributes_effect',
element_id,
b.thunk(b.array(values)),
b.literal(context.state.analysis.css.hash)
)
);
if (needs_isolation) {
context.state.init.push(isolated);
return false;
} else if (is_reactive) {
const id = context.state.scope.generate('spread_attributes'); const id = context.state.scope.generate('spread_attributes');
context.state.init.push(b.let(id)); context.state.init.push(b.let(id));
context.state.update.push(
b.stmt( const update = b.stmt(
b.assignment( b.assignment(
'=', '=',
b.id(id), b.id(id),
@ -393,10 +383,17 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
b.literal(context.state.analysis.css.hash) b.literal(context.state.analysis.css.hash)
) )
) )
)
); );
if (needs_isolation) {
context.state.init.push(serialize_update(update));
return false;
}
context.state.update.push(update);
return true; return true;
} else { }
context.state.init.push( context.state.init.push(
b.stmt( b.stmt(
b.call( b.call(
@ -409,7 +406,6 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
) )
); );
return false; return false;
}
} }
/** /**

@ -184,20 +184,6 @@ export function spread_attributes(element, prev, attrs, lowercase_attributes, cs
return next; return next;
} }
/**
* @param {Element} node
* @param {() => Record<string, unknown>[]} attrs
* @param {string} css_hash
*/
export function spread_dynamic_element_attributes_effect(node, attrs, css_hash) {
/** @type {Record<string, any> | undefined} */
var current;
render_effect(() => {
current = spread_dynamic_element_attributes(node, current, attrs(), css_hash);
});
}
/** /**
* @param {Element} node * @param {Element} node
* @param {Record<string, unknown> | undefined} prev * @param {Record<string, unknown> | undefined} prev

Loading…
Cancel
Save