tsx:add fragment support

This commit is contained in:
pengfei.zhou
2021-09-02 12:03:19 +08:00
committed by osborn
parent aeff0a06dc
commit 03633a7bea
11 changed files with 170 additions and 155 deletions

View File

@@ -2,12 +2,12 @@ import { Group, View } from "../ui/view";
import { layoutConfig } from "./layoutconfig";
import { ClassType } from "./types";
export const jsx = {
createElement: function <T extends View>(
export namespace jsx {
export function createElement<T extends View>(
constructor: ClassType<T>,
config: Partial<T> | null,
...children: View[]
): T {
) {
const e = new constructor();
e.layoutConfig = layoutConfig().fit()
if (config) {
@@ -15,7 +15,13 @@ export const jsx = {
}
if (children && children.length > 0) {
if (e instanceof Group) {
children.forEach((child) => e.addChild(child));
children.forEach((child) => {
if (child instanceof Fragment) {
child.children.forEach(c => e.addChild(c))
} else {
e.addChild(child)
}
});
} else {
throw new Error(
`Can only add child to group view, do not support ${constructor.name}`
@@ -23,7 +29,8 @@ export const jsx = {
}
}
return e;
},
}
export class Fragment extends Group { }
}
declare global {