[IMP] qweb: turn handlers into function expressions only

For the sake of consistency with vanilla JS, and to allow some things
that were previously not possible.
This commit is contained in:
Samuel Degueldre
2021-11-12 12:56:07 +01:00
committed by Aaron Bohy
parent 756d32daa0
commit bca6afeb90
33 changed files with 280 additions and 227 deletions
+1 -1
View File
@@ -93,7 +93,7 @@ export class ComponentNode<T extends typeof Component = any> implements VNode<Co
this.level = parent ? parent.level + 1 : 0;
applyDefaultProps(props, C);
this.component = new C(props, app.env, this) as any;
this.renderFn = app.getTemplate(C.template).bind(null, this.component, this);
this.renderFn = app.getTemplate(C.template).bind(this.component, this.component, this);
if (C.style) {
applyStyles(C);
}
+5 -6
View File
@@ -26,12 +26,11 @@ export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarg
}
}
}
if (typeof data[0] === "function") {
data[0](ev);
} else if (data[0].__owl__) {
const method = data[1];
const args = data[2] || [];
data[0].__owl__.component[method](...args, ev);
// If handler is empty, the array slot 0 will also be empty, and data will not have the property 0
// We check this rather than data[0] being truthy (or typeof function) so that it crashes
// as expected when there is a handler expression that evaluates to a falsy value
if (Object.hasOwnProperty.call(data, 0)) {
data[0].call(data[1] ? data[1].__owl__.component : null, ev);
}
return stopped;
};