| @@ -3,6 +3,7 import _WidgetBase = require("dijit/_Wid | |||||
| 3 | import _AttachMixin = require("dijit/_AttachMixin"); |
|
3 | import _AttachMixin = require("dijit/_AttachMixin"); | |
| 4 | import { Rendition, isNode } from "./traits"; |
|
4 | import { Rendition, isNode } from "./traits"; | |
| 5 | import registry = require("dijit/registry"); |
|
5 | import registry = require("dijit/registry"); | |
|
|
6 | import on = require("dojo/on"); | |||
| 6 |
|
7 | |||
| 7 | // type Handle = dojo.Handle; |
|
8 | // type Handle = dojo.Handle; | |
| 8 |
|
9 | |||
| @@ -65,7 +66,7 export abstract class DjxWidgetBase<Attr | |||||
| 65 | this._eventHandlers.forEach(({ eventName, handlerMethod }) => { |
|
66 | this._eventHandlers.forEach(({ eventName, handlerMethod }) => { | |
| 66 | const handler = this[handlerMethod as keyof this]; |
|
67 | const handler = this[handlerMethod as keyof this]; | |
| 67 | if (typeof handler === "function") |
|
68 | if (typeof handler === "function") | |
| 68 |
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 | export function isRendition(v: any): v is Rendition { |
|
65 | export function isRendition(v: any): v is Rendition { | |
| 66 |
return typeof v |
|
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 | <K extends string, |
|
218 | <K extends string, | |
| 219 | T extends DjxWidgetBase<any, { [p in E]: EV }>, |
|
219 | T extends DjxWidgetBase<any, { [p in E]: EV }>, | |
| 220 | EV extends Event |
|
220 | EV extends Event | |
| @@ -223,8 +223,6 export const on = <E extends string>(eve | |||||
| 223 | key: K, |
|
223 | key: K, | |
| 224 | _descriptor: TypedPropertyDescriptor<(eventObj: EV) => void> | TypedPropertyDescriptor<() => void> |
|
224 | _descriptor: TypedPropertyDescriptor<(eventObj: EV) => void> | TypedPropertyDescriptor<() => void> | |
| 225 | ): any => { |
|
225 | ): any => { | |
| 226 | if(!target._eventHandlers) |
|
226 | const handlers = eventNames.map(eventName => ({ eventName, handlerMethod: key })) | |
| 227 | target._eventHandlers = [{ eventName, handlerMethod: key }]; |
|
227 | target._eventHandlers = target._eventHandlers ? target._eventHandlers.concat(handlers) : handlers; | |
| 228 | else |
|
|||
| 229 | target._eventHandlers.push({ eventName, handlerMethod: key }); |
|
|||
| 230 | }; |
|
228 | }; | |
| @@ -64,8 +64,8 export class MyWidget extends djbase(Djx | |||||
| 64 | _onCounterInc(evt: Event & { detail: number; x?: number; }) { |
|
64 | _onCounterInc(evt: Event & { detail: number; x?: number; }) { | |
| 65 | } |
|
65 | } | |
| 66 |
|
66 | |||
| 67 | @on("click") |
|
67 | @on("click", "keydown") | |
| 68 | protected _onClick() { |
|
68 | protected _onClick(event: MouseEvent | KeyboardEvent) { | |
| 69 |
|
69 | |||
| 70 | } |
|
70 | } | |
| 71 | } No newline at end of file |
|
71 | } | |
General Comments 0
You need to be logged in to leave comments.
Login now
