[IMP] component: add .bind suffix to props for easy binding

This commit is contained in:
Géry Debongnie
2021-12-01 15:51:00 +01:00
committed by Samuel Degueldre
parent 7b95315b87
commit 4cde06d685
4 changed files with 129 additions and 6 deletions
+18
View File
@@ -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,
};