diff --git a/web/static/src/ts/core/qweb_vdom.ts b/web/static/src/ts/core/qweb_vdom.ts index c46e347d..97b54873 100644 --- a/web/static/src/ts/core/qweb_vdom.ts +++ b/web/static/src/ts/core/qweb_vdom.ts @@ -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}]};`); + } } }; diff --git a/web/static/tests/core/__snapshots__/qweb_vdom.test.ts.snap b/web/static/tests/core/__snapshots__/qweb_vdom.test.ts.snap index 0d307c56..ecae79c3 100644 --- a/web/static/tests/core/__snapshots__/qweb_vdom.test.ts.snap +++ b/web/static/tests/core/__snapshots__/qweb_vdom.test.ts.snap @@ -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: \`