Lint and format src/compiler/compile/render_dom/wrappers/Element/EventHandler.js

pull/8569/head
Simon Holthausen 3 years ago
parent 87420085e1
commit 920f6383c8

@ -1,9 +1,8 @@
import { b, x, p } from 'code-red';
const TRUE = x `true`;
const FALSE = x `false`;
const TRUE = x`true`;
const FALSE = x`false`;
/** */
export default class EventHandlerWrapper {
/** @type {import('../../../nodes/EventHandler.js').default} */
node;
@ -19,7 +18,7 @@ export default class EventHandlerWrapper {
this.parent = parent;
if (!node.expression) {
this.parent.renderer.add_to_context(node.handler_name.name);
this.parent.renderer.component.partly_hoisted.push(b `
this.parent.renderer.component.partly_hoisted.push(b`
function ${node.handler_name.name}(event) {
@bubble.call(this, $$self, event);
}
@ -34,7 +33,7 @@ export default class EventHandlerWrapper {
: block.renderer.reference(this.node.handler_name);
if (this.node.reassigned) {
block.maintain_context = true;
return x `function () { if (@is_function(${snippet})) ${snippet}.apply(this, arguments); }`;
return x`function () { if (@is_function(${snippet})) ${snippet}.apply(this, arguments); }`;
}
return snippet;
}
@ -45,27 +44,25 @@ export default class EventHandlerWrapper {
*/
render(block, target) {
let snippet = this.get_snippet(block);
if (this.node.modifiers.has('preventDefault'))
snippet = x `@prevent_default(${snippet})`;
if (this.node.modifiers.has('stopPropagation'))
snippet = x `@stop_propagation(${snippet})`;
if (this.node.modifiers.has('preventDefault')) snippet = x`@prevent_default(${snippet})`;
if (this.node.modifiers.has('stopPropagation')) snippet = x`@stop_propagation(${snippet})`;
if (this.node.modifiers.has('stopImmediatePropagation'))
snippet = x `@stop_immediate_propagation(${snippet})`;
if (this.node.modifiers.has('self'))
snippet = x `@self(${snippet})`;
if (this.node.modifiers.has('trusted'))
snippet = x `@trusted(${snippet})`;
snippet = x`@stop_immediate_propagation(${snippet})`;
if (this.node.modifiers.has('self')) snippet = x`@self(${snippet})`;
if (this.node.modifiers.has('trusted')) snippet = x`@trusted(${snippet})`;
const args = [];
const opts = ['nonpassive', 'passive', 'once', 'capture'].filter((mod) => this.node.modifiers.has(mod));
const opts = ['nonpassive', 'passive', 'once', 'capture'].filter((mod) =>
this.node.modifiers.has(mod)
);
if (opts.length) {
if (opts.length === 1 && opts[0] === 'capture') {
args.push(TRUE);
} else {
args.push(
x`{ ${opts.map((opt) => (opt === 'nonpassive' ? p`passive: false` : p`${opt}: true`))} }`
);
}
else {
args.push(x `{ ${opts.map((opt) => (opt === 'nonpassive' ? p `passive: false` : p `${opt}: true`))} }`);
}
}
else if (block.renderer.options.dev) {
} else if (block.renderer.options.dev) {
args.push(FALSE);
}
if (block.renderer.options.dev) {
@ -73,10 +70,6 @@ export default class EventHandlerWrapper {
args.push(this.node.modifiers.has('stopPropagation') ? TRUE : FALSE);
args.push(this.node.modifiers.has('stopImmediatePropagation') ? TRUE : FALSE);
}
block.event_listeners.push(x `@listen(${target}, "${this.node.name}", ${snippet}, ${args})`);
block.event_listeners.push(x`@listen(${target}, "${this.node.name}", ${snippet}, ${args})`);
}
}

Loading…
Cancel
Save