##// END OF EJS Templates
Added tag v1.0.0-rc3 for changeset 6d80d7901b4c
Added tag v1.0.0-rc3 for changeset 6d80d7901b4c

File last commit:

r7:d14fb562b896 default
r9:11edf8e36b92 default
Show More
WidgetContext.ts
43 lines | 1.2 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / tsx / WidgetContext.ts
import dom = require("dojo/dom-construct");
import { argumentNotNull } from "@implab/core-amd/safe";
import _WidgetBase = require("dijit/_WidgetBase");
import { BuildContextBase } from "./BuildContextBase";
type _WidgetBaseConstructor = typeof _WidgetBase;
export class WidgetContext extends BuildContextBase {
widgetClass: _WidgetBaseConstructor;
_instance: _WidgetBase | undefined;
constructor(widgetClass: _WidgetBaseConstructor) {
super();
argumentNotNull(widgetClass, "widgetClass");
this.widgetClass = widgetClass;
}
_addChild(child: any): void {
if (!this._instance || !this._instance.containerNode)
throw new Error("Widget doesn't support adding children");
dom.place(this.getChildDom(child), this._instance.containerNode);
}
_setAttrs(attrs: object): void {
this._instance?.set(attrs);
}
_create(attrs: object, children: any[]) {
this._instance = new this.widgetClass(this._attrs);
if (children)
children.forEach(x => this._addChild(x));
}
_getDomElement() {
if (!this._instance)
throw new Error("The instance of the widget isn't created");
return this._instance.domNode;
}
}