refactoring, work on environment

This commit is contained in:
Géry Debongnie
2019-01-23 14:28:41 +01:00
parent 08938d2334
commit 76fedae5a9
18 changed files with 138 additions and 63 deletions
+5 -5
View File
@@ -1,16 +1,16 @@
import { init } from "../../../libs/snabbdom/src/snabbdom";
import sdListeners from "../../../libs/snabbdom/src/modules/eventlisteners";
import sdAttrs from "../../../libs/snabbdom/src/modules/attributes";
import sdListeners from "../../../libs/snabbdom/src/modules/eventlisteners";
import { init } from "../../../libs/snabbdom/src/snabbdom";
import { VNode } from "../../../libs/snabbdom/src/vnode";
import QWeb from "./qweb_vdom";
const patch = init([sdListeners, sdAttrs]);
export interface WidgetEnv {
export interface WEnv {
qweb: QWeb;
}
export default class Widget<T extends WidgetEnv> {
export default class Widget<T extends WEnv> {
name: string = "widget";
template: string = "<div></div>";
vnode: VNode | null = null;
@@ -49,7 +49,7 @@ export default class Widget<T extends WidgetEnv> {
async mount(target?: HTMLElement): Promise<VNode> {
await this.willStart();
this.env!.qweb.addTemplate(this.name, this.template);
this.env.qweb.addTemplate(this.name, this.template);
delete this.template;
const vnode = await this.render();
+2 -2
View File
@@ -640,7 +640,7 @@ const forEachDirective: Directive = {
const onDirective: Directive = {
name: "on",
priority: 90,
atNodeCreation({ ctx, fullName, value, nodeID }) {
atNodeCreation({ ctx, fullName, value, nodeID, qweb }) {
const eventName = fullName.slice(5);
let extraArgs;
let handler = value.replace(/\(.*\)/, function(args) {
@@ -649,7 +649,7 @@ const onDirective: Directive = {
});
ctx.addLine(
`p${nodeID}.on = {${eventName}: context['${handler}'].bind(context${
extraArgs ? ", " + extraArgs : ""
extraArgs ? ", " + qweb._formatExpression(extraArgs) : ""
})}`
);
}