mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] component: add .bind suffix to props for easy binding
This commit is contained in:
committed by
Samuel Degueldre
parent
7b95315b87
commit
4cde06d685
@@ -124,6 +124,23 @@ export function safeOutput(value: any): ReturnType<typeof toggler> {
|
||||
return toggler(safeKey, block);
|
||||
}
|
||||
|
||||
let boundFunctions = new WeakMap();
|
||||
|
||||
function bind(ctx: any, fn: Function): Function {
|
||||
let component = ctx.__owl__.component;
|
||||
let boundFnMap = boundFunctions.get(component);
|
||||
if (!boundFnMap) {
|
||||
boundFnMap = new WeakMap();
|
||||
boundFunctions.set(component, boundFnMap);
|
||||
}
|
||||
let boundFn = boundFnMap.get(fn);
|
||||
if (!boundFn) {
|
||||
boundFn = fn.bind(component);
|
||||
boundFnMap.set(fn, boundFn);
|
||||
}
|
||||
return boundFn;
|
||||
}
|
||||
|
||||
export const UTILS = {
|
||||
withDefault,
|
||||
zero: Symbol("zero"),
|
||||
@@ -137,4 +154,5 @@ export const UTILS = {
|
||||
toNumber,
|
||||
validateProps,
|
||||
safeOutput,
|
||||
bind,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user