[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
+18
View File
@@ -163,6 +163,8 @@ export class QWeb extends EventBus {
slots = {};
nextSlotId = 1;
isUpdating: boolean = false;
constructor(data?: string) {
super();
if (data) {
@@ -306,6 +308,22 @@ export class QWeb extends EventBus {
return (<HTMLElement>result.elm).outerHTML;
}
/**
* Force all widgets connected to this QWeb instance to rerender themselves.
*
* This method is mostly useful for external code that want to modify the
* application in some cases. For example, a router plugin.
*/
forceUpdate() {
this.isUpdating = true;
Promise.resolve().then(() => {
if (this.isUpdating) {
this.isUpdating = false;
this.trigger("update");
}
});
}
_compile(name: string, elem: Element, parentContext?: Context): CompiledTemplate {
const isDebug = elem.attributes.hasOwnProperty("t-debug");
const ctx = new Context(name);