|
|
|
|
@ -28,7 +28,9 @@ 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)
|
|
|
|
|
@ -36,10 +38,13 @@ export function add_action(block, target, action) {
|
|
|
|
|
: 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}))`);
|
|
|
|
|
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)`;
|
|
|
|
|
@ -49,7 +54,3 @@ export function add_action(block, target, action) {
|
|
|
|
|
block.chunks.update.push(b`if (${condition}) ${id}.update.call(null, ${snippet});`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|