tsx:support array in children
This commit is contained in:
@@ -1,7 +1,21 @@
|
||||
import { Group } from "../ui/view";
|
||||
import { Group, View } from "../ui/view";
|
||||
import { layoutConfig } from "./layoutconfig";
|
||||
export var jsx;
|
||||
(function (jsx) {
|
||||
function addElement(group, v) {
|
||||
if (v instanceof Array) {
|
||||
v.forEach(e => addElement(group, e));
|
||||
}
|
||||
else if (v instanceof Fragment) {
|
||||
v.children.forEach(e => addElement(group, e));
|
||||
}
|
||||
else if (v instanceof View) {
|
||||
group.addChild(v);
|
||||
}
|
||||
else {
|
||||
throw new Error(`Can only use view as child`);
|
||||
}
|
||||
}
|
||||
function createElement(constructor, config, ...children) {
|
||||
const e = new constructor();
|
||||
e.layoutConfig = layoutConfig().fit();
|
||||
@@ -11,12 +25,7 @@ export var jsx;
|
||||
if (children && children.length > 0) {
|
||||
if (e instanceof Group) {
|
||||
children.forEach((child) => {
|
||||
if (child instanceof Fragment) {
|
||||
child.children.forEach(c => e.addChild(c));
|
||||
}
|
||||
else {
|
||||
e.addChild(child);
|
||||
}
|
||||
addElement(e, child);
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
Reference in New Issue
Block a user