mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
fix widget class
This commit is contained in:
+16
-9
@@ -1,10 +1,11 @@
|
||||
import QWeb from "./qweb_vdom";
|
||||
|
||||
// import {init} from "../libs/snabbdom/src/snabbdom"
|
||||
// import sdProps from "../libs/snabbdom/src/modules/props"
|
||||
// import sdListeners from "../libs/snabbdom/src/modules/eventlisteners"
|
||||
import {init} from "../libs/snabbdom/src/snabbdom"
|
||||
import sdProps from "../libs/snabbdom/src/modules/props"
|
||||
import sdListeners from "../libs/snabbdom/src/modules/eventlisteners"
|
||||
import { VNode } from "../libs/snabbdom/src/vnode";
|
||||
|
||||
// const patch = init([sdProps, sdListeners]);
|
||||
const patch = init([sdProps, sdListeners]);
|
||||
|
||||
export interface Env {
|
||||
qweb: QWeb;
|
||||
@@ -15,11 +16,12 @@ export interface Env {
|
||||
export default class Widget {
|
||||
name: string = "widget";
|
||||
template: string = "<div></div>";
|
||||
vnode: VNode | null = null;
|
||||
|
||||
parent: Widget | null;
|
||||
children: Widget[] = [];
|
||||
env: Env | null = null;
|
||||
el: ChildNode | null = null;
|
||||
el: HTMLElement | null = null;
|
||||
state: Object = {};
|
||||
refs: { [key: string]: Widget } = {};
|
||||
|
||||
@@ -53,6 +55,8 @@ export default class Widget {
|
||||
this.env!.qweb.addTemplate(this.name, this.template);
|
||||
delete this.template;
|
||||
await this.render();
|
||||
|
||||
|
||||
target.appendChild(this.el!);
|
||||
}
|
||||
|
||||
@@ -82,10 +86,13 @@ export default class Widget {
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
async render() {
|
||||
// const vnode = await this.env!.qweb.render(this.name, this);
|
||||
// patch(this.el, vnode);
|
||||
|
||||
// this._setElement(fragment.firstChild!);
|
||||
let vnode = await this.env!.qweb.render(this.name, this);
|
||||
if (!this.el) {
|
||||
this.el = document.createElement(vnode.sel!);
|
||||
}
|
||||
patch(this.vnode || this.el, vnode);
|
||||
this.vnode = vnode;
|
||||
|
||||
}
|
||||
|
||||
// private _setElement(el: ChildNode) {
|
||||
|
||||
Reference in New Issue
Block a user