mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[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:
committed by
Aaron Bohy
parent
756d32daa0
commit
bca6afeb90
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user