##// END OF EJS Templates
@on decorator registers handlers directry on domNode, added support to multiple events in one decorator...
cin -
r85:35a7b6319ebe v1.2.6 default
parent child
Show More
@@ -3,6 +3,7 import _WidgetBase = require("dijit/_Wid
3 3 import _AttachMixin = require("dijit/_AttachMixin");
4 4 import { Rendition, isNode } from "./traits";
5 5 import registry = require("dijit/registry");
6 import on = require("dojo/on");
6 7
7 8 // type Handle = dojo.Handle;
8 9
@@ -65,7 +66,7 export abstract class DjxWidgetBase<Attr
65 66 this._eventHandlers.forEach(({ eventName, handlerMethod }) => {
66 67 const handler = this[handlerMethod as keyof this];
67 68 if (typeof handler === "function")
68 this.on(eventName, handler.bind(this));
69 on(this.domNode, eventName, handler.bind(this));
69 70 });
70 71 }
71 72
@@ -63,7 +63,7 export function isWidget(v: any): v is _
63 63 }
64 64
65 65 export function isRendition(v: any): v is Rendition {
66 return typeof v === "object" && typeof v.getDomElement === "function";
66 return typeof v && typeof v.getDomElement === "function";
67 67 }
68 68
69 69 /**
@@ -214,7 +214,7 export function watch<T extends Stateful
214 214 * }
215 215 * ```
216 216 */
217 export const on = <E extends string>(eventName: E) =>
217 export const on = <E extends string>(...eventNames: E[]) =>
218 218 <K extends string,
219 219 T extends DjxWidgetBase<any, { [p in E]: EV }>,
220 220 EV extends Event
@@ -223,8 +223,6 export const on = <E extends string>(eve
223 223 key: K,
224 224 _descriptor: TypedPropertyDescriptor<(eventObj: EV) => void> | TypedPropertyDescriptor<() => void>
225 225 ): any => {
226 if(!target._eventHandlers)
227 target._eventHandlers = [{ eventName, handlerMethod: key }];
228 else
229 target._eventHandlers.push({ eventName, handlerMethod: key });
226 const handlers = eventNames.map(eventName => ({ eventName, handlerMethod: key }))
227 target._eventHandlers = target._eventHandlers ? target._eventHandlers.concat(handlers) : handlers;
230 228 };
@@ -64,8 +64,8 export class MyWidget extends djbase(Djx
64 64 _onCounterInc(evt: Event & { detail: number; x?: number; }) {
65 65 }
66 66
67 @on("click")
68 protected _onClick() {
67 @on("click", "keydown")
68 protected _onClick(event: MouseEvent | KeyboardEvent) {
69 69
70 70 }
71 71 } No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now