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

pull/8569/head
Simon Holthausen 3 years ago
parent 00a3597fb4
commit 5c7b9594dd

@ -8,7 +8,6 @@ import handle_select_value_binding from './handle_select_value_binding';
import { regex_box_size } from '../../../../utils/patterns';
/** */
export default class BindingWrapper {
/** @type {import('../../../nodes/Binding.js').default} */
node = undefined;
@ -59,7 +58,13 @@ export default class BindingWrapper {
this.binding_group = get_binding_group(parent.renderer, this, block);
}
// view to model
this.handler = get_event_handler(this, parent.renderer, block, this.object, this.node.raw_expression);
this.handler = get_event_handler(
this,
parent.renderer,
block,
this.object,
this.node.raw_expression
);
this.snippet = this.node.expression.manipulate(block);
this.is_readonly = this.node.is_readonly;
this.needs_lock = this.node.name === 'currentTime'; // TODO others?
@ -86,13 +91,13 @@ export default class BindingWrapper {
this.node.expression.template_scope.dependencies_for_name
.get(object)
.forEach((name) => dependencies.add(name));
}
else {
} else {
dependencies.add(object);
}
const result = new Set(dependencies);
dependencies.forEach((dependency) => {
const indirect_dependencies = this.parent.renderer.component.indirect_dependencies.get(dependency);
const indirect_dependencies =
this.parent.renderer.component.indirect_dependencies.get(dependency);
if (indirect_dependencies) {
indirect_dependencies.forEach((indirect_dependency) => {
result.add(indirect_dependency);
@ -110,8 +115,7 @@ export default class BindingWrapper {
* @param {import('estree').Identifier} lock
*/
render(block, lock) {
if (this.is_readonly)
return;
if (this.is_readonly) return;
const { parent } = this;
/** @type {any[]} */
@ -128,16 +132,17 @@ export default class BindingWrapper {
}
if (parent.node.name === 'input') {
const type = parent.node.get_static_attribute_value('type');
if (type === null ||
if (
type === null ||
type === '' ||
type === 'text' ||
type === 'email' ||
type === 'password' ||
type === 'search' ||
type === 'url') {
type === 'url'
) {
update_conditions.push(x`${parent.var}.${this.node.name} !== ${this.snippet}`);
}
else if (type === 'number') {
} else if (type === 'number') {
update_conditions.push(x`@to_number(${parent.var}.${this.node.name}) !== ${this.snippet}`);
}
}
@ -149,8 +154,9 @@ export default class BindingWrapper {
case 'group': {
block.renderer.add_to_context('$$binding_groups');
this.binding_group.add_element(block, this.parent.var);
if (( /** @type {import('../Element.js').default} */(this.parent)).has_dynamic_value) {
update_or_condition = ( /** @type {import('../Element.js').default} */(this.parent)).dynamic_value_condition;
if (/** @type {import('../Element.js').default} */ (this.parent).has_dynamic_value) {
update_or_condition = /** @type {import('../Element.js').default} */ (this.parent)
.dynamic_value_condition;
}
break;
}
@ -193,15 +199,13 @@ export default class BindingWrapper {
if (update_dom) {
if (update_conditions.length > 0) {
let condition = update_conditions.reduce((lhs, rhs) => x`${lhs} && ${rhs}`);
if (update_or_condition)
condition = x `${update_or_condition} || (${condition})`;
if (update_or_condition) condition = x`${update_or_condition} || (${condition})`;
block.chunks.update.push(b`
if (${condition}) {
${update_dom}
}
`);
}
else {
} else {
block.chunks.update.push(update_dom);
}
}
@ -213,8 +217,7 @@ export default class BindingWrapper {
${mount_dom}
}
`);
}
else {
} else {
block.chunks.mount.push(mount_dom);
}
}
@ -243,7 +246,8 @@ function get_dom_updater(element, binding, mounting) {
}
if (binding.node.name === 'group') {
const type = node.get_static_attribute_value('type');
const condition = type === 'checkbox'
const condition =
type === 'checkbox'
? x`~(${binding.snippet} || []).indexOf(${element.var}.__value)`
: x`${element.var}.__value === ${binding.snippet}`;
return b`${element.var}.checked = ${condition};`;
@ -287,8 +291,7 @@ function get_binding_group(renderer, binding, block) {
if (context) {
key = context.object.name;
name = context.property.name;
}
else {
} else {
key = dep;
name = dep;
}
@ -346,11 +349,18 @@ function get_binding_group(renderer, binding, block) {
type: 'ArrayExpression',
elements: contexts.map((name) => block.renderer.reference(name))
};
block.chunks.init.push(b `${local_name} = @init_binding_group_dynamic(${binding_group}[${index}], ${indexes})`);
block.chunks.update.push(b `if (${block.renderer.dirty(Array.from(list_dependencies))}) ${local_name}.u(${indexes})`);
}
else {
block.chunks.init.push(b `${local_name} = @init_binding_group(${binding_group}[${index}])`);
block.chunks.init.push(
b`${local_name} = @init_binding_group_dynamic(${binding_group}[${index}], ${indexes})`
);
block.chunks.update.push(
b`if (${block.renderer.dirty(
Array.from(list_dependencies)
)}) ${local_name}.u(${indexes})`
);
} else {
block.chunks.init.push(
b`${local_name} = @init_binding_group(${binding_group}[${index}])`
);
}
block.chunks.hydrate.push(b`${local_name}.p(${elements.get(block)})`);
block.chunks.destroy.push(b`${local_name}.r()`);
@ -386,8 +396,7 @@ function get_event_handler(binding, renderer, block, name, lhs) {
if (store) {
set_store = b`${store}.set(${`$${store}`});`;
}
}
else {
} else {
const object = get_object(lhs);
if (object.name[0] === '$') {
const store = object.name.slice(1);
@ -449,7 +458,3 @@ function get_value_from_dom(_renderer, element, binding, contextual_dependencies
// everything else
return x`this.${name}`;
}

Loading…
Cancel
Save