##// END OF EJS Templates
Added tag v1.2.2 for changeset bc7556143fe5
Added tag v1.2.2 for changeset bc7556143fe5

File last commit:

r77:bc7556143fe5 v1.2.2 default
r78:2c641d60ffc9 default
Show More
DjxWidgetBase.ts
110 lines | 3.8 KiB | video/mp2t | TypeScriptLexer
/ djx / src / main / ts / tsx / DjxWidgetBase.ts
cin
Switched to @implab/dojo-typings
r71 import { AbstractConstructor, djbase, djclass } from "../declare";
cin
Converted to subproject djx, removed dojo-typings
r65 import _WidgetBase = require("dijit/_WidgetBase");
import _AttachMixin = require("dijit/_AttachMixin");
import { Rendition, isNode, startupWidgets } from "./traits";
import registry = require("dijit/registry");
// type Handle = dojo.Handle;
export interface EventArgs {
bubbles?: boolean;
cancelable?: boolean;
composed?: boolean;
}
cin
Switched to @implab/dojo-typings
r71 export interface DjxWidgetBase<Attrs = {}, Events extends { [name in keyof Events]: Event } = {}> extends
_WidgetBase<Events> {
cin
temp commit, working on @on() decorator
r72
cin
implemented @on("event-name") decorator for event handlers
r73 /** This property is declared only for type inference to work, it is never assigned
* and should not be used.
*/
cin
temp commit, working on @on() decorator
r72 readonly _eventMap: Events & GlobalEventHandlersEventMap;
cin
Switched to @implab/dojo-typings
r71 }
cin
Converted to subproject djx, removed dojo-typings
r65
cin
Switched to @implab/dojo-typings
r71 type _super = {
startup(): void;
cin
Converted to subproject djx, removed dojo-typings
r65 }
@djclass
cin
Switched to @implab/dojo-typings
r71 export abstract class DjxWidgetBase<Attrs = {}, Events = {}> extends djbase<_super, _AttachMixin>(_WidgetBase, _AttachMixin) {
cin
Converted to subproject djx, removed dojo-typings
r65
cin
implemented @on("event-name") decorator for event handlers
r73 /** The list of pairs of event and method names. When the widget is created all methods from
* this list will be connected to corresponding events.
*/
cin
temp commit, working on @on() decorator
r72 _eventHandlers: Array<{
cin
implemented @on("event-name") decorator for event handlers
r73 eventName: string,
handlerMethod: keyof any;
cin
temp commit, working on @on() decorator
r72 }> = [];
cin
Converted to subproject djx, removed dojo-typings
r65 buildRendering() {
this.domNode = this.render().getDomNode();
super.buildRendering();
// now we should get assigned data-dojo-attach-points
// place the contents of the original srcNode to the containerNode
const src = this.srcNodeRef;
const dest = this.containerNode;
cin
implemented @on("event-name") decorator for event handlers
r73 // the donNode is constructed now we need to connect event handlers
this._connectEventHandlers();
cin
Converted to subproject djx, removed dojo-typings
r65 if (src && dest) {
while (src.firstChild)
dest.appendChild(src.firstChild);
}
}
abstract render(): Rendition<HTMLElement>;
cin
temp commit, working on @on() decorator
r72 private _connectEventHandlers() {
this._eventHandlers.forEach(({eventName, handlerMethod}) => {
cin
implemented @on("event-name") decorator for event handlers
r73 const handler = this[handlerMethod as keyof this];
if (typeof handler === "function")
cin
bind event handler methods marked with `@on` before subscribing the event
r77 this.on(eventName, handler.bind(this));
cin
temp commit, working on @on() decorator
r72 });
}
cin
Converted to subproject djx, removed dojo-typings
r65 _processTemplateNode<T extends (Element | Node | _WidgetBase)>(
baseNode: T,
cin
Switched to @implab/dojo-typings
r71 getAttrFunc: (baseNode: T, attr: string) => any,
cin
Converted to subproject djx, removed dojo-typings
r65 // tslint:disable-next-line: ban-types
attachFunc: (node: T, type: string, func?: Function) => dojo.Handle
): boolean {
if (isNode(baseNode)) {
const w = registry.byNode(baseNode);
if (w) {
// from dijit/_WidgetsInTemplateMixin
this._processTemplateNode(w,
cin
Switched to @implab/dojo-typings
r71 (n, p) => n.get(p as any), // callback to get a property of a widget
cin
Converted to subproject djx, removed dojo-typings
r65 (widget, type, callback) => {
if (!callback)
throw new Error("The callback must be specified");
// callback to do data-dojo-attach-event to a widget
if (type in widget) {
// back-compat, remove for 2.0
return widget.connect(widget, type, callback as EventListener);
} else {
// 1.x may never hit this branch, but it's the default for 2.0
return widget.on(type, callback);
}
});
// don't process widgets internals
return false;
}
}
return super._processTemplateNode(baseNode, getAttrFunc, attachFunc);
}
/** Starts current widget and all its supporting widgets (placed outside
* `containerNode`) and child widgets (placed inside `containerNode`)
*/
startup() {
// startup supporting widgets
registry.findWidgets(this.domNode, this.containerNode).forEach(w => w.startup());
super.startup();
}
}