more binding stuff

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

@ -141,6 +141,7 @@ export default class EachBlockWrapper extends Wrapper {
this.block.bindings.set(prop.key.name, {
object: this.vars.each_block_value,
property: this.index_name,
modifier: prop.modifier,
snippet: prop.modifier(x`${this.vars.each_block_value}[${this.index_name}]` as Node),
store,
tail: prop.modifier(x`[${this.index_name}]` as Node)

@ -244,30 +244,34 @@ function get_event_handler(
const contextual_dependencies = new Set(binding.node.expression.contextual_dependencies);
const context = block.bindings.get(name);
let set_store;
if (context) {
const { object, property } = context;
const { object, property, modifier, store } = context;
if (lhs.type === 'Identifier') {
lhs = x`${object}[${property}]`;
lhs = modifier(x`${object}[${property}]`);
contextual_dependencies.add(object.name);
contextual_dependencies.add(property.name);
}
}
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});
`;
if (store) {
set_store = b`${store}.set(${object.name});`;
}
} else {
const object = get_object(lhs);
if (object.name[0] === '$') {
const store = object.name.slice(1);
set_store = b`${store}.set(${object.name});`;
}
}
let mutation = b`
${lhs} = ${value};
${set_store}
`;
return {
uses_context: binding.node.is_contextual || binding.node.expression.uses_context, // TODO this is messy
mutation,

Loading…
Cancel
Save