##// END OF EJS Templates
DjxFragment converted to functionl component...
cin -
r59:bcdd096122ff default
parent child
Show More
@@ -1,5 +1,5
1 1 import { isNull, mixin } from "@implab/core-amd/safe";
2 import { isPlainObject, isNode, isBuildContext, DojoNodePosition, BuildContext, isInPage } from "./traits";
2 import { isPlainObject, isNode, isBuildContext, DojoNodePosition, BuildContext, isInPage, isWidget } from "./traits";
3 3
4 4 import dom = require("dojo/dom-construct");
5 5 import registry = require("dijit/registry");
@@ -29,7 +29,7 export abstract class BuildContextBase<T
29 29 }
30 30 }
31 31
32 getChildDom(v: any) {
32 protected getItemDom(v: any) {
33 33 const tv = typeof v;
34 34 if (tv === "string" || tv === "number" || v instanceof RegExp || v instanceof Date) {
35 35 return document.createTextNode(v.toString());
@@ -37,6 +37,10 export abstract class BuildContextBase<T
37 37 return v;
38 38 } else if (isBuildContext(v)) {
39 39 return v.getDomNode();
40 } else if(isWidget(v)) {
41 return v.domNode;
42 } else if(tv === "boolean" || v === null || v === undefined) {
43 return document.createComment(`[${tv} ${String(v)}]`);
40 44 } else {
41 45 throw new Error("Invalid parameter");
42 46 }
@@ -1,18 +1,6
1 import { _Widget } from "./WidgetContext";
2 import { MapOf } from "@implab/core-amd/interfaces";
3 import { prototype } from "../declare";
4
5 /** Special widget used to create a document fragment */
6 export class DjxFragment implements _Widget {
7
8 domNode: Node;
9
10 containerNode: Node;
11
12 constructor() {
13 this.domNode = this.containerNode = document.createDocumentFragment();
14 }
15 buildRendering() {
16 // this function marks this class as _Widget
17 }
1 /** Special functional component used to create a document fragment */
2 export function DjxFragment({children}: {children: Node[]}){
3 const fragment = document.createDocumentFragment();
4 if (children)
5 children.forEach(child => fragment.appendChild(child));
18 6 } No newline at end of file
@@ -19,9 +19,9 export class FunctionComponentContext ex
19 19
20 20 _create(attrs: object, children: any[]) {
21 21 const _attrs: any = attrs || {};
22 _attrs.children = children.map(x => this.getChildDom(x));
22 _attrs.children = children.map(x => this.getItemDom(x));
23 23
24 this._node = this.getChildDom(this._component.call(null, _attrs));
24 this._node = this.getItemDom(this._component.call(null, _attrs));
25 25 }
26 26
27 27 _getDomNode() {
@@ -17,7 +17,7 export class HtmlElementContext extends
17 17 _addChild(child: any): void {
18 18 if (!this._element)
19 19 throw new Error("The HTML element isn't created");
20 dom.place(this.getChildDom(child), this._element);
20 dom.place(this.getItemDom(child), this._element);
21 21 }
22 22
23 23 _create(attrs: object, children: any[]) {
@@ -45,14 +45,14 export class WidgetContext extends Build
45 45 throw new Error("The widget doesn't have neither addChild nor containerNode");
46 46
47 47 // the current widget isn't started, it's children shouldn't start too
48 dom.place(this.getChildDom(child), instance.containerNode);
48 dom.place(this.getItemDom(child), instance.containerNode);
49 49 }
50 50 } else {
51 51 if (!instance.containerNode)
52 52 throw new Error("The widget doesn't have neither addChild nor containerNode");
53 53
54 54 // the current widget isn't started, it's children shouldn't start too
55 dom.place(this.getChildDom(child), instance.containerNode);
55 dom.place(this.getItemDom(child), instance.containerNode);
56 56 }
57 57 }
58 58
@@ -65,7 +65,7 export class WidgetContext extends Build
65 65
66 66 // render children to the DocumentFragment
67 67 const content = document.createDocumentFragment();
68 children.forEach(child => content.appendChild(this.getChildDom(child)));
68 children.forEach(child => content.appendChild(this.getItemDom(child)));
69 69
70 70 // set the content property to the parameters of the widget
71 71 const _attrs = { ...attrs, content };
General Comments 0
You need to be logged in to leave comments. Login now