import QWeb from "./qweb_vdom"; import { init } from "../libs/snabbdom/src/snabbdom"; import sdListeners from "../libs/snabbdom/src/modules/eventlisteners"; import sdAttrs from "../libs/snabbdom/src/modules/attributes"; import { VNode } from "../libs/snabbdom/src/vnode"; const patch = init([sdListeners, sdAttrs]); export interface Env { qweb: QWeb; services: { [key: string]: any }; [key: string]: any; } export default class Widget { name: string = "widget"; template: string = "
"; vnode: VNode | null = null; parent: Widget | null = null; children: Widget[] = []; env: Env; el: HTMLElement | null = null; state: Object = {}; refs: { [key: string]: Widget } = {}; //-------------------------------------------------------------------------- // Lifecycle //-------------------------------------------------------------------------- constructor(parent: Widget | Env, props?: any) { if (parent instanceof Widget) { this.parent = parent; parent.children.push(this); this.env = Object.create(parent.env); } else { this.env = parent; } } async willStart() {} mounted() {} willUnmount() {} destroyed() {} //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- async mount(target?: HTMLElement): Promise