[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:
Géry Debongnie
2019-07-30 14:36:51 +02:00
parent f6369f9750
commit cd9cac1246
4 changed files with 34 additions and 4 deletions
+1 -1
View File
@@ -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
View File
@@ -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);
});
});