mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] qweb: add forceUpdate method
and make sure it only triggers an update once for multiple calls in same call stack
This commit is contained in:
@@ -3539,7 +3539,7 @@ describe("environment and plugins", () => {
|
||||
env.someFlag = true;
|
||||
bus.on("some-event", null, () => {
|
||||
env.someFlag = !env.someFlag;
|
||||
env.qweb.trigger("update");
|
||||
env.qweb.forceUpdate();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
+14
-2
@@ -1,5 +1,5 @@
|
||||
import { QWeb } from "../../src/qweb/index";
|
||||
import { normalize, renderToDOM, renderToString, trim } from "../helpers";
|
||||
import { normalize, renderToDOM, renderToString, trim, nextTick } from "../helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Setup and helpers
|
||||
@@ -505,7 +505,7 @@ describe("t-call (template calling", () => {
|
||||
qweb.addTemplate("sub", "<span>ok</span>");
|
||||
qweb.addTemplate("caller", '<div><t t-if="flag" t-call="sub"/></div>');
|
||||
const expected = "<div><span>ok</span></div>";
|
||||
expect(renderToString(qweb, "caller", {flag: true})).toBe(expected);
|
||||
expect(renderToString(qweb, "caller", { flag: true })).toBe(expected);
|
||||
});
|
||||
|
||||
test("t-call not allowed on a non t node", () => {
|
||||
@@ -1178,3 +1178,15 @@ describe("debugging", () => {
|
||||
console.log = consoleLog;
|
||||
});
|
||||
});
|
||||
|
||||
describe("update on event bus", () => {
|
||||
test("two consecutive forceUpdates only causes one listener update", async () => {
|
||||
const fn = jest.fn();
|
||||
qweb.on("update", null, fn);
|
||||
qweb.forceUpdate();
|
||||
qweb.forceUpdate();
|
||||
expect(fn).toBeCalledTimes(0);
|
||||
await nextTick();
|
||||
expect(fn).toBeCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user