fix issue with event binding in some cases

This commit is contained in:
Géry Debongnie
2019-02-14 10:51:29 +01:00
parent 6331d9e2ac
commit 85889d6cd2
2 changed files with 14 additions and 10 deletions
+12 -6
View File
@@ -725,12 +725,18 @@ const onDirective: Directive = {
extraArgs = args.slice(1, -1);
return "";
});
ctx.addLine(
`extra.handlers[${nodeID}] = extra.handlers[${nodeID}] || context['${handler}'].bind(owner${
extraArgs ? ", " + qweb._formatExpression(extraArgs) : ""
});`
);
ctx.addLine(`p${nodeID}.on = {${eventName}: extra.handlers[${nodeID}]};`);
if (extraArgs) {
ctx.addLine(
`p${nodeID}.on = {${eventName}: context['${handler}'].bind(owner, ${qweb._formatExpression(
extraArgs
)})};`
);
} else {
ctx.addLine(
`extra.handlers[${nodeID}] = extra.handlers[${nodeID}] || context['${handler}'].bind(owner);`
);
ctx.addLine(`p${nodeID}.on = {${eventName}: extra.handlers[${nodeID}]};`);
}
}
};
@@ -904,8 +904,7 @@ exports[`t-on can bind handlers with arguments 1`] = `
let h = this.h;
let c1 = [], p1 = {};
let vn1 = h('button', p1, c1);
extra.handlers[1] = extra.handlers[1] || context['add'].bind(owner, 5);
p1.on = {click: extra.handlers[1]};
p1.on = {click: context['add'].bind(owner, 5)};
c1.push({text: \`Click\`});
return vn1;
}"
@@ -939,8 +938,7 @@ exports[`t-on can bind handlers with loop variable as argument 1`] = `
let c6 = [], p6 = {};
let vn6 = h('a', p6, c6);
c5.push(vn6);
extra.handlers[6] = extra.handlers[6] || context['activate'].bind(owner, context['action']);
p6.on = {click: extra.handlers[6]};
p6.on = {click: context['activate'].bind(owner, context['action'])};
c6.push({text: \`link\`});
}
c1.push({text: \`