##// END OF EJS Templates
Switched to dojo-typings...
Switched to dojo-typings Added TNode type parameter to BuildContext custom dojo typings are going to be removed

File last commit:

r22:a1ab2b5975ad v1.0.0-rc10 default
r22:a1ab2b5975ad v1.0.0-rc10 default
Show More
BuildContextBase.ts
76 lines | 2.0 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / tsx / BuildContextBase.ts
cin
Added DjxFragment...
r19 import { isNull, mixin } from "@implab/core-amd/safe";
cin
Added placeAt() method to BuildContext
r14 import { isPlainObject, isNode, isBuildContext, DojoNodePosition, BuildContext } from "./traits";
cin
sync
r7
cin
Added placeAt() method to BuildContext
r14 import dom = require("dojo/dom-construct");
cin
Switched to dojo-typings...
r22 export abstract class BuildContextBase<TNode extends Node> implements BuildContext<TNode> {
cin
sync
r7 _attrs = {};
_children = new Array();
_created: boolean = false;
visitNext(v: any) {
if (isNull(v))
return;
if (isPlainObject(v)) {
if (this._created)
this._setAttrs(v);
else
mixin(this._attrs, v);
cin
tsx: Added auto unfolding arrays of children when constructing DOM
r13 } else if (v instanceof Array) {
v.forEach(x => this._addChild(x));
cin
sync
r7 } else {
if (this._created)
this._addChild(v);
else
this._children.push(v);
}
}
getChildDom(v: any) {
const tv = typeof v;
if (tv === "string" || tv === "number" || tv === "boolean" || v instanceof RegExp || v instanceof Date) {
return document.createTextNode(v.toString());
} else if (isNode(v)) {
return v;
} else if (isBuildContext(v)) {
cin
Added DjxFragment...
r19 return v.getDomNode();
cin
sync
r7 } else {
throw new Error("Invalid parameter");
}
}
cin
Switched to dojo-typings...
r22 abstract _getDomNode(): TNode;
cin
sync
r7
ensureCreated() {
if (!this._created) {
this._create(this._attrs, this._children);
this._children = [];
this._attrs = {};
this._created = true;
}
}
cin
Added DjxFragment...
r19 /** @deprecated use getDomNode() */
cin
sync
r7 getDomElement() {
cin
Added DjxFragment...
r19 return this.getDomNode();
}
getDomNode() {
cin
sync
r7 this.ensureCreated();
cin
Added DjxFragment...
r19 return this._getDomNode();
cin
sync
r7 }
cin
Added placeAt() method to BuildContext
r14 placeAt(refNode: string | Node, position?: DojoNodePosition) {
cin
Added DjxFragment...
r19 dom.place(this.getDomNode(), refNode, position);
cin
Added placeAt() method to BuildContext
r14 }
cin
sync
r7 abstract _addChild(child: any): void;
abstract _setAttrs(attrs: object): void;
abstract _create(attrs: object, children: any[]): void;
}