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