[REF] qweb: revamp event management

Closes #111
This commit is contained in:
Aaron Bohy
2019-05-31 14:03:34 +02:00
committed by Géry Debongnie
parent fe23e76341
commit 2f9d7ea58f
6 changed files with 107 additions and 74 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ exports[`class and style attributes with t-widget dynamic t-att-style is properl
w4 = new W4(owner, props4);
context.__owl__.cmap[4] = w4.__owl__.id;
def3 = w4._prepare();
def3 = def3.then(vnode=>{vnode.data.hook = {create(_, vn){vn.elm.style = _5}};let pvnode=h(vnode.sel, {key: 4, hook: {insert(vn) {let nvn=w4._mount(vnode, pvnode.elm);pvnode.elm=nvn.elm;},remove() {},destroy(vn) {w4.destroy();}}});c1[_2_index]=pvnode;w4.__owl__.pvnode = pvnode;});
def3 = def3.then(vnode=>{vnode.data.hook = {create(_, vn){vn.elm.style = _5;}};let pvnode=h(vnode.sel, {key: 4, hook: {insert(vn) {let nvn=w4._mount(vnode, pvnode.elm);pvnode.elm=nvn.elm;},remove() {},destroy(vn) {w4.destroy();}}});c1[_2_index]=pvnode;w4.__owl__.pvnode = pvnode;});
} else {
def3 = def3 || w4._updateProps(props4, extra.forceUpdate, extra.patchQueue);
def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};w4.el.style=_5;let pvnode=w4.__owl__.pvnode;c1[_2_index]=pvnode;});
+15 -13
View File
@@ -1450,28 +1450,30 @@ describe("class and style attributes with t-widget", () => {
describe("other directives with t-widget", () => {
test("t-on works as expected", async () => {
let n = 0;
env.qweb.addTemplate(
"ParentWidget",
`<div><t t-widget="child" t-on-customevent="someMethod"/></div>`
);
expect.assertions(4);
env.qweb.addTemplates(`
<templates>
<div t-name="ParentWidget"><t t-widget="child" t-on-custom-event="someMethod"/></div>
</templates>
`);
class ParentWidget extends Widget {
widgets = { child: Child };
someMethod(arg) {
expect(arg).toBe(43);
n++;
n = 0;
someMethod(ev) {
expect(ev.detail).toBe(43);
this.n++;
}
}
class Child extends Widget {}
const widget = new ParentWidget(env);
await widget.mount(fixture);
let child = children(widget)[0];
expect(n).toBe(0);
child.trigger("customevent", 43);
expect(n).toBe(1);
expect(widget.n).toBe(0);
child.trigger("custom-event", 43);
expect(widget.n).toBe(1);
child.destroy();
child.trigger("customevent", 43);
expect(n).toBe(1);
child.trigger("custom-event", 43);
expect(widget.n).toBe(1);
});
test("t-if works with t-widget", async () => {