more binding stuff

pull/3539/head
Richard Harris 6 years ago
parent 29f6437533
commit 8f233aee8b

@ -20,7 +20,8 @@ export default class Attribute extends Node {
is_spread: boolean;
is_true: boolean;
is_static: boolean;
is_synthetic: boolean;
// TODO apparently unnecessary?
// is_synthetic: boolean;
expression?: Expression;
chunks: Array<Text | Expression>;
dependencies: Set<string>;
@ -33,7 +34,7 @@ export default class Attribute extends Node {
this.name = null;
this.is_spread = true;
this.is_true = false;
this.is_synthetic = false;
// this.is_synthetic = false;
this.expression = new Expression(component, this, scope, info.expression);
this.dependencies = this.expression.dependencies;
@ -46,7 +47,7 @@ export default class Attribute extends Node {
this.name = info.name;
this.is_true = info.value === true;
this.is_static = true;
this.is_synthetic = info.synthetic;
// this.is_synthetic = info.synthetic;
this.dependencies = new Set();

@ -77,7 +77,9 @@ export default class Expression {
scope: Scope;
scope_map: WeakMap<Node, Scope>;
is_synthetic: boolean;
// TODO apparently unnecessary?
// is_synthetic: boolean;
declarations: (Node | Node[])[] = [];
uses_context = false;
@ -96,7 +98,7 @@ export default class Expression {
this.template_scope = template_scope;
this.owner = owner;
// @ts-ignore
this.is_synthetic = owner.is_synthetic;
// this.is_synthetic = owner.is_synthetic;
const { dependencies, contextual_dependencies } = this;
@ -233,8 +235,7 @@ export default class Expression {
declarations,
scope_map: map,
template_scope,
owner,
is_synthetic
owner
} = this;
let scope = this.scope;
@ -271,7 +272,7 @@ export default class Expression {
dependencies.add(name);
component.add_reference(name); // TODO is this redundant/misplaced?
}
} else if (!is_synthetic && is_contextual(component, template_scope, name)) {
} else if (is_contextual(component, template_scope, name)) {
this.replace(x`#ctx.${node}`);
}

@ -228,12 +228,6 @@ function get_binding_group(renderer: Renderer, value: Node) {
return index;
}
function mutate_store(store, value, tail) {
return tail
? b`${store}.update($$value => ($$value${tail} = ${value}, $$value));`
: b`${store}.set(${value});`;
}
function get_event_handler(
binding: BindingWrapper,
renderer: Renderer,
@ -259,75 +253,26 @@ function get_event_handler(
contextual_dependencies.add(object.name);
contextual_dependencies.add(property.name);
} else {
// (lhs as MemberExpression).object = x`${object}[${property}]`;
}
}
let mutation = b`${lhs} = ${value}`;
const object = get_object(lhs);
if (object.name[0] === '$') {
const store = object.name.slice(1);
mutation = b`
${mutation}
${store}.set(${object.name});
`;
}
return {
uses_context: binding.node.is_contextual || binding.node.expression.uses_context, // TODO this is messy
mutation: b`${lhs} = ${value}`,
mutation,
contextual_dependencies
};
// if (lhs.type === 'MemberExpression') {
// return {
// uses_context: binding.node.is_contextual || binding.node.expression.uses_context, // TODO this is messy
// mutation: b`${lhs} = ${value}`,
// contextual_dependencies
// };
// } else {
// }
// const binding_info = block.bindings.get(name);
// console.log(binding_info);
// let store = binding.object[0] === '$' ? binding.object.slice(1) : null;
// let tail = null;
// if (binding.node.expression.node.type === 'MemberExpression') {
// // const { start, end } = get_tail(binding.node.expression.node);
// // tail = renderer.component.source.slice(start, end);
// tail = binding.node.expression.node.object;
// }
// if (binding.node.is_contextual) {
// const binding = block.bindings.get(name);
// const { object, property, snippet } = binding;
// if (binding.store) {
// store = binding.store;
// tail = x`${binding.tail}.${tail}`;
// }
// return {
// uses_context: true,
// mutation: store
// ? mutate_store(store, value, tail)
// : b`${snippet} = ${value};`,
// contextual_dependencies: new Set([object.name, property.name])
// };
// }
// const mutation = store
// ? mutate_store(store, value, tail)
// : b`${snippet} = ${value};`;
// if (binding.node.expression.node.type === 'MemberExpression') {
// return {
// uses_context: binding.node.expression.uses_context,
// mutation,
// contextual_dependencies: binding.node.expression.contextual_dependencies,
// snippet
// };
// }
// return {
// uses_context: false,
// mutation,
// contextual_dependencies: new Set()
// };
}
function get_value_from_dom(

Loading…
Cancel
Save