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:
+15
-8
@@ -1,10 +1,11 @@
|
|||||||
import QWeb from "./qweb_vdom";
|
import QWeb from "./qweb_vdom";
|
||||||
|
|
||||||
// import {init} from "../libs/snabbdom/src/snabbdom"
|
import {init} from "../libs/snabbdom/src/snabbdom"
|
||||||
// import sdProps from "../libs/snabbdom/src/modules/props"
|
import sdProps from "../libs/snabbdom/src/modules/props"
|
||||||
// import sdListeners from "../libs/snabbdom/src/modules/eventlisteners"
|
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 {
|
export interface Env {
|
||||||
qweb: QWeb;
|
qweb: QWeb;
|
||||||
@@ -15,11 +16,12 @@ export interface Env {
|
|||||||
export default class Widget {
|
export default class Widget {
|
||||||
name: string = "widget";
|
name: string = "widget";
|
||||||
template: string = "<div></div>";
|
template: string = "<div></div>";
|
||||||
|
vnode: VNode | null = null;
|
||||||
|
|
||||||
parent: Widget | null;
|
parent: Widget | null;
|
||||||
children: Widget[] = [];
|
children: Widget[] = [];
|
||||||
env: Env | null = null;
|
env: Env | null = null;
|
||||||
el: ChildNode | null = null;
|
el: HTMLElement | null = null;
|
||||||
state: Object = {};
|
state: Object = {};
|
||||||
refs: { [key: string]: Widget } = {};
|
refs: { [key: string]: Widget } = {};
|
||||||
|
|
||||||
@@ -53,6 +55,8 @@ export default class Widget {
|
|||||||
this.env!.qweb.addTemplate(this.name, this.template);
|
this.env!.qweb.addTemplate(this.name, this.template);
|
||||||
delete this.template;
|
delete this.template;
|
||||||
await this.render();
|
await this.render();
|
||||||
|
|
||||||
|
|
||||||
target.appendChild(this.el!);
|
target.appendChild(this.el!);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,10 +86,13 @@ export default class Widget {
|
|||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
async render() {
|
async render() {
|
||||||
// const vnode = await this.env!.qweb.render(this.name, this);
|
let vnode = await this.env!.qweb.render(this.name, this);
|
||||||
// patch(this.el, vnode);
|
if (!this.el) {
|
||||||
|
this.el = document.createElement(vnode.sel!);
|
||||||
|
}
|
||||||
|
patch(this.vnode || this.el, vnode);
|
||||||
|
this.vnode = vnode;
|
||||||
|
|
||||||
// this._setElement(fragment.firstChild!);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private _setElement(el: ChildNode) {
|
// private _setElement(el: ChildNode) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Widget from "../src/core/widget";
|
import Widget from "../src/core/widget";
|
||||||
import QWeb from "../src/core/qweb";
|
import QWeb from "../src/core/qweb_vdom";
|
||||||
|
|
||||||
function makeWidget(W: typeof Widget): Widget {
|
function makeWidget(W: typeof Widget): Widget {
|
||||||
const env = {
|
const env = {
|
||||||
|
|||||||
Reference in New Issue
Block a user