Lint and format src/compiler/compile/render_dom/wrappers/shared/add_actions.js

pull/8569/head
Simon Holthausen 3 years ago
parent 44529665f0
commit e5d02f9dd6

@ -28,28 +28,29 @@ export function add_action(block, target, action) {
snippet = expression.manipulate(block);
dependencies = expression.dynamic_dependencies();
}
const id = block.get_unique_name(`${action.name.replace(regex_invalid_variable_identifier_characters, '_')}_action`);
const id = block.get_unique_name(
`${action.name.replace(regex_invalid_variable_identifier_characters, '_')}_action`
);
block.add_variable(id);
const [obj, ...properties] = action.name.split('.');
const fn = is_contextual(action.component, template_scope, obj)
? block.renderer.reference(obj)
: obj;
if (properties.length) {
const member_expression = properties.reduce((lhs, rhs) => x `${lhs}.${rhs}`, fn);
block.event_listeners.push(x `@action_destroyer(${id} = ${member_expression}(${target}, ${snippet}))`);
}
else {
block.event_listeners.push(x `@action_destroyer(${id} = ${fn}.call(null, ${target}, ${snippet}))`);
const member_expression = properties.reduce((lhs, rhs) => x`${lhs}.${rhs}`, fn);
block.event_listeners.push(
x`@action_destroyer(${id} = ${member_expression}(${target}, ${snippet}))`
);
} else {
block.event_listeners.push(
x`@action_destroyer(${id} = ${fn}.call(null, ${target}, ${snippet}))`
);
}
if (dependencies && dependencies.length > 0) {
let condition = x `${id} && @is_function(${id}.update)`;
let condition = x`${id} && @is_function(${id}.update)`;
if (dependencies.length > 0) {
condition = x `${condition} && ${block.renderer.dirty(dependencies)}`;
condition = x`${condition} && ${block.renderer.dirty(dependencies)}`;
}
block.chunks.update.push(b `if (${condition}) ${id}.update.call(null, ${snippet});`);
block.chunks.update.push(b`if (${condition}) ${id}.update.call(null, ${snippet});`);
}
}

Loading…
Cancel
Save