jsx support use function as component
This commit is contained in:
@@ -412,6 +412,9 @@ export abstract class View implements Modeling {
|
||||
}
|
||||
})
|
||||
}
|
||||
static isViewClass() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class Superview extends View {
|
||||
|
@@ -420,6 +420,9 @@ export abstract class View implements Modeling {
|
||||
}
|
||||
})
|
||||
}
|
||||
static isViewClass() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
export abstract class Superview extends View {
|
||||
subviewById(id: string): View | undefined {
|
||||
|
@@ -8,27 +8,49 @@ export namespace jsx {
|
||||
config: Partial<T> | null,
|
||||
...children: any[]
|
||||
) {
|
||||
const e = new constructor();
|
||||
if (e instanceof Fragment) {
|
||||
return children
|
||||
}
|
||||
e.layoutConfig = layoutConfig().fit()
|
||||
if (config) {
|
||||
e.apply(config)
|
||||
}
|
||||
if (children && children.length > 0) {
|
||||
if (children.length === 1) {
|
||||
children = children[0]
|
||||
if (!!(constructor as any).isViewClass) {
|
||||
const e = new constructor();
|
||||
if (e instanceof Fragment) {
|
||||
return children
|
||||
}
|
||||
if (Reflect.has(e, "innerElement")) {
|
||||
Reflect.set(e, "innerElement", children, e)
|
||||
} else {
|
||||
throw new Error(
|
||||
`Do not support ${constructor.name} for ${children}`
|
||||
);
|
||||
e.layoutConfig = layoutConfig().fit()
|
||||
if (config) {
|
||||
e.apply(config)
|
||||
}
|
||||
if (children && children.length > 0) {
|
||||
if (children.length === 1) {
|
||||
children = children[0]
|
||||
}
|
||||
if (Reflect.has(e, "innerElement")) {
|
||||
Reflect.set(e, "innerElement", children, e)
|
||||
} else {
|
||||
throw new Error(
|
||||
`Do not support ${constructor.name} for ${children}`
|
||||
);
|
||||
}
|
||||
}
|
||||
return e;
|
||||
} else {
|
||||
const f = constructor as Function
|
||||
const e = Reflect.apply(f, undefined, [config])
|
||||
if (e instanceof Fragment) {
|
||||
return children
|
||||
}
|
||||
if (children && children.length > 0) {
|
||||
if (children.length === 1) {
|
||||
children = children[0]
|
||||
}
|
||||
if (Reflect.has(e, "innerElement")) {
|
||||
Reflect.set(e, "innerElement", children, e)
|
||||
} else {
|
||||
throw new Error(
|
||||
`Do not support add child for ${e.viewType()}`
|
||||
);
|
||||
}
|
||||
}
|
||||
return e
|
||||
}
|
||||
return e;
|
||||
|
||||
}
|
||||
export class Fragment extends Group { }
|
||||
}
|
||||
|
Reference in New Issue
Block a user