|
|
|
@ -127,7 +127,6 @@ export default class Component extends Node {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const allContexts = new Set();
|
|
|
|
|
const statements: string[] = [];
|
|
|
|
|
|
|
|
|
|
const name_initial_data = block.getUniqueName(`${name}_initial_data`);
|
|
|
|
@ -135,10 +134,6 @@ export default class Component extends Node {
|
|
|
|
|
let name_updating: string;
|
|
|
|
|
let beforecreate: string = null;
|
|
|
|
|
|
|
|
|
|
// const eventHandlers = this.attributes
|
|
|
|
|
// .filter((a: Node) => a.type === 'EventHandler')
|
|
|
|
|
// .map(a => mungeEventHandler(compiler, this, a, block, allContexts));
|
|
|
|
|
|
|
|
|
|
const updates: string[] = [];
|
|
|
|
|
|
|
|
|
|
const usesSpread = !!this.attributes.find(a => a.isSpread);
|
|
|
|
@ -146,7 +141,6 @@ export default class Component extends Node {
|
|
|
|
|
const attributeObject = usesSpread
|
|
|
|
|
? '{}'
|
|
|
|
|
: stringifyProps(
|
|
|
|
|
// this.attributes.map(attr => `${attr.name}: ${attr.value}`)
|
|
|
|
|
this.attributes.map(attr => `${attr.name}: ${attr.getValue()}`)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@ -237,10 +231,6 @@ export default class Component extends Node {
|
|
|
|
|
this.bindings.forEach((binding: Binding) => {
|
|
|
|
|
let { name: key } = getObject(binding.value.node);
|
|
|
|
|
|
|
|
|
|
binding.value.contexts.forEach(context => {
|
|
|
|
|
allContexts.add(context);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let setFromChild;
|
|
|
|
|
|
|
|
|
|
if (block.contexts.has(key)) { // TODO remove block.contexts
|
|
|
|
@ -492,51 +482,6 @@ export default class Component extends Node {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mungeEventHandler(compiler: DomGenerator, node: Node, handler: Node, block: Block, allContexts: Set<string>) {
|
|
|
|
|
let body;
|
|
|
|
|
|
|
|
|
|
if (handler.expression) {
|
|
|
|
|
compiler.addSourcemapLocations(handler.expression);
|
|
|
|
|
|
|
|
|
|
// TODO try out repetition between this and element counterpart
|
|
|
|
|
const flattened = flattenReference(handler.expression.callee);
|
|
|
|
|
if (!validCalleeObjects.has(flattened.name)) {
|
|
|
|
|
// allow event.stopPropagation(), this.select() etc
|
|
|
|
|
// TODO verify that it's a valid callee (i.e. built-in or declared method)
|
|
|
|
|
compiler.code.prependRight(
|
|
|
|
|
handler.expression.start,
|
|
|
|
|
`${block.alias('component')}.`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let usesState = false;
|
|
|
|
|
|
|
|
|
|
handler.expression.arguments.forEach((arg: Node) => {
|
|
|
|
|
const { contexts } = block.contextualise(arg, null, true);
|
|
|
|
|
if (contexts.has('state')) usesState = true;
|
|
|
|
|
|
|
|
|
|
contexts.forEach(context => {
|
|
|
|
|
allContexts.add(context);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
body = deindent`
|
|
|
|
|
${usesState && `const ctx = #component.get();`}
|
|
|
|
|
[✂${handler.expression.start}-${handler.expression.end}✂];
|
|
|
|
|
`;
|
|
|
|
|
} else {
|
|
|
|
|
body = deindent`
|
|
|
|
|
#component.fire('${handler.name}', event);
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
name: handler.name,
|
|
|
|
|
var: block.getUniqueName(`${node.var}_${handler.name}`),
|
|
|
|
|
body
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isComputed(node: Node) {
|
|
|
|
|
while (node.type === 'MemberExpression') {
|
|
|
|
|
if (node.computed) return true;
|
|
|
|
|