[IMP] qweb,component: make QWeb an event bus

closes #197
This commit is contained in:
Géry Debongnie
2019-06-22 14:44:09 +02:00
parent 63a8fcd7e2
commit 8c8ffb6a6b
6 changed files with 170 additions and 85 deletions
+19 -2
View File
@@ -134,6 +134,19 @@ export class Component<T extends Env, Props extends {}, State extends {}> {
parent.__owl__.children[id] = this;
} else {
this.env = parent;
this.env.qweb.on("update", this, () => {
if (this.__owl__.isMounted) {
this.render(true);
}
if (this.__owl__.isDestroyed) {
// this is unlikely to happen, but if a root widget is destroyed,
// we want to remove our subscription. The usual way to do that
// would be to perform some check in the destroy method, but since
// it is very performance sensitive, and since this is a rare event,
// we simply do it lazily
this.env.qweb.off("update", this);
}
});
}
this.__owl__ = {
id: id,
@@ -593,7 +606,9 @@ export class Component<T extends Env, Props extends {}, State extends {}> {
for (let i = 0, l = propsDef.length; i < l; i++) {
if (!(propsDef[i] in props)) {
throw new Error(
`Missing props '${propsDef[i]}' (component '${this.constructor.name}')`
`Missing props '${propsDef[i]}' (component '${
this.constructor.name
}')`
);
}
}
@@ -603,7 +618,9 @@ export class Component<T extends Env, Props extends {}, State extends {}> {
if (!(propName in props)) {
if (propsDef[propName] && !propsDef[propName].optional) {
throw new Error(
`Missing props '${propName}' (component '${this.constructor.name}')`
`Missing props '${propName}' (component '${
this.constructor.name
}')`
);
} else {
break;