# HG changeset patch # User cin # Date 2021-09-06 13:36:54 # Node ID 35a7b6319ebe24973fe10b8d82c19d3d86857b4e # Parent 68eba315d2abfa087b9b91d7f16809c3712d7043 @on decorator registers handlers directry on domNode, added support to multiple events in one decorator fixed isRendition failing on null objects diff --git a/djx/src/main/ts/tsx/DjxWidgetBase.ts b/djx/src/main/ts/tsx/DjxWidgetBase.ts --- a/djx/src/main/ts/tsx/DjxWidgetBase.ts +++ b/djx/src/main/ts/tsx/DjxWidgetBase.ts @@ -3,6 +3,7 @@ import _WidgetBase = require("dijit/_Wid import _AttachMixin = require("dijit/_AttachMixin"); import { Rendition, isNode } from "./traits"; import registry = require("dijit/registry"); +import on = require("dojo/on"); // type Handle = dojo.Handle; @@ -65,7 +66,7 @@ export abstract class DjxWidgetBase { const handler = this[handlerMethod as keyof this]; if (typeof handler === "function") - this.on(eventName, handler.bind(this)); + on(this.domNode, eventName, handler.bind(this)); }); } diff --git a/djx/src/main/ts/tsx/traits.ts b/djx/src/main/ts/tsx/traits.ts --- a/djx/src/main/ts/tsx/traits.ts +++ b/djx/src/main/ts/tsx/traits.ts @@ -63,7 +63,7 @@ export function isWidget(v: any): v is _ } export function isRendition(v: any): v is Rendition { - return typeof v === "object" && typeof v.getDomElement === "function"; + return typeof v && typeof v.getDomElement === "function"; } /** @@ -214,7 +214,7 @@ export function watch(eventName: E) => +export const on = (...eventNames: E[]) => , EV extends Event @@ -223,8 +223,6 @@ export const on = (eve key: K, _descriptor: TypedPropertyDescriptor<(eventObj: EV) => void> | TypedPropertyDescriptor<() => void> ): any => { - if(!target._eventHandlers) - target._eventHandlers = [{ eventName, handlerMethod: key }]; - else - target._eventHandlers.push({ eventName, handlerMethod: key }); + const handlers = eventNames.map(eventName => ({ eventName, handlerMethod: key })) + target._eventHandlers = target._eventHandlers ? target._eventHandlers.concat(handlers) : handlers; }; diff --git a/djx/src/test/ts/view/MyWidget.tsx b/djx/src/test/ts/view/MyWidget.tsx --- a/djx/src/test/ts/view/MyWidget.tsx +++ b/djx/src/test/ts/view/MyWidget.tsx @@ -64,8 +64,8 @@ export class MyWidget extends djbase(Djx _onCounterInc(evt: Event & { detail: number; x?: number; }) { } - @on("click") - protected _onClick() { + @on("click", "keydown") + protected _onClick(event: MouseEvent | KeyboardEvent) { } } \ No newline at end of file