implement destroy, add tests

This commit is contained in:
Géry Debongnie
2019-01-16 23:03:51 +01:00
parent f0d529139b
commit 0f8cdfa87d
3 changed files with 53 additions and 10 deletions
+12 -8
View File
@@ -25,7 +25,9 @@ export default class Widget {
this.parent = parent;
if (parent) {
parent.children.push(this);
this.setEnvironment(parent.env);
if (parent.env) {
this.setEnvironment(parent.env);
}
}
}
@@ -46,16 +48,18 @@ export default class Widget {
target.appendChild(this.el!);
}
destroy() {}
setEnvironment(env: Env | null) {
this.env = env ? Object.create(env) : null;
if (this.env) {
this.env.qweb.addTemplate(this.name, this.template);
delete this.template;
destroy() {
if (this.el) {
this.el.remove();
}
}
setEnvironment(env: Env) {
this.env = Object.create(env);
env.qweb.addTemplate(this.name, this.template);
delete this.template;
}
async updateState(newState: Object) {
Object.assign(this.state, newState);
await this.render();