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