WidgetContext.ts
40 lines
| 1.1 KiB
| video/mp2t
|
TypeScriptLexer
cin
|
r0 | import dom = require("dojo/dom-construct"); | ||
import { argumentNotNull, isNull, mixin } from "@implab/core-amd/safe"; | ||||
import _WidgetBase = require("dijit/_WidgetBase"); | ||||
import { _WidgetBaseConstructor, isNode } from "./traits"; | ||||
import { BuildContextBase } from "./BuildContextBase"; | ||||
export class WidgetContext extends BuildContextBase { | ||||
widgetClass: _WidgetBaseConstructor; | ||||
_instance: _WidgetBase; | ||||
constructor(widgetClass: _WidgetBaseConstructor) { | ||||
super(); | ||||
argumentNotNull(widgetClass, "widgetClass"); | ||||
this.widgetClass = widgetClass; | ||||
} | ||||
_addChild(child: any): void { | ||||
if (!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() { | ||||
return this._instance.domNode; | ||||
} | ||||
} | ||||