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