jsx support use function as component
This commit is contained in:
10
doric-js/lib/src/native/navigator.d.ts
vendored
10
doric-js/lib/src/native/navigator.d.ts
vendored
@@ -4,11 +4,11 @@ import { ClassType } from "../util/types";
|
||||
export declare function internalScheme(context: BridgeContext, panelClass: ClassType<Panel>): string;
|
||||
export declare function navigator(context: BridgeContext): {
|
||||
push: (source: string | ClassType<Panel>, config?: {
|
||||
alias?: string;
|
||||
animated?: boolean;
|
||||
extra?: object;
|
||||
singlePage?: boolean;
|
||||
}) => Promise<any>;
|
||||
alias?: string | undefined;
|
||||
animated?: boolean | undefined;
|
||||
extra?: object | undefined;
|
||||
singlePage?: boolean | undefined;
|
||||
} | undefined) => Promise<any>;
|
||||
pop: (animated?: boolean) => Promise<any>;
|
||||
popSelf: (animated?: boolean) => Promise<any>;
|
||||
popToRoot: (animated?: boolean) => Promise<any>;
|
||||
|
8
doric-js/lib/src/native/network.d.ts
vendored
8
doric-js/lib/src/native/network.d.ts
vendored
@@ -20,8 +20,8 @@ export interface IResponse {
|
||||
}
|
||||
export declare function network(context: BridgeContext): {
|
||||
request: (config: IRequest) => Promise<IResponse>;
|
||||
get: (url: string, config?: IRequest) => Promise<IResponse>;
|
||||
post: (url: string, data?: object | string, config?: IRequest) => Promise<IResponse>;
|
||||
put: (url: string, data?: object | string, config?: IRequest) => Promise<IResponse>;
|
||||
delete: (url: string, data?: object | string, config?: IRequest) => Promise<IResponse>;
|
||||
get: (url: string, config?: IRequest | undefined) => Promise<IResponse>;
|
||||
post: (url: string, data?: string | object | undefined, config?: IRequest | undefined) => Promise<IResponse>;
|
||||
put: (url: string, data?: string | object | undefined, config?: IRequest | undefined) => Promise<IResponse>;
|
||||
delete: (url: string, data?: string | object | undefined, config?: IRequest | undefined) => Promise<IResponse>;
|
||||
};
|
||||
|
6
doric-js/lib/src/native/storage.d.ts
vendored
6
doric-js/lib/src/native/storage.d.ts
vendored
@@ -1,7 +1,7 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
export declare function storage(context: BridgeContext): {
|
||||
setItem: (key: string, value: string, zone?: string) => Promise<any>;
|
||||
getItem: (key: string, zone?: string) => Promise<string>;
|
||||
remove: (key: string, zone?: string) => Promise<any>;
|
||||
setItem: (key: string, value: string, zone?: string | undefined) => Promise<any>;
|
||||
getItem: (key: string, zone?: string | undefined) => Promise<string>;
|
||||
remove: (key: string, zone?: string | undefined) => Promise<any>;
|
||||
clear: (zone: string) => Promise<any>;
|
||||
};
|
||||
|
1
doric-js/lib/src/ui/view.d.ts
vendored
1
doric-js/lib/src/ui/view.d.ts
vendored
@@ -145,6 +145,7 @@ export declare abstract class View implements Modeling {
|
||||
doAnimation(context: BridgeContext, animation: IAnimation): Promise<void>;
|
||||
clearAnimation(context: BridgeContext, animation: IAnimation): Promise<void>;
|
||||
cancelAnimation(context: BridgeContext, animation: IAnimation): Promise<void>;
|
||||
static isViewClass(): boolean;
|
||||
}
|
||||
export declare abstract class Superview extends View {
|
||||
subviewById(id: string): View | undefined;
|
||||
|
@@ -253,6 +253,9 @@ export class View {
|
||||
}
|
||||
});
|
||||
}
|
||||
static isViewClass() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
Property,
|
||||
|
2
doric-js/lib/src/util/jsx.d.ts
vendored
2
doric-js/lib/src/util/jsx.d.ts
vendored
@@ -1,7 +1,7 @@
|
||||
import { Group, View } from "../ui/view";
|
||||
import { ClassType } from "./types";
|
||||
export declare namespace jsx {
|
||||
function createElement<T extends View>(constructor: ClassType<T>, config: Partial<T> | null, ...children: any[]): any[] | T;
|
||||
function createElement<T extends View>(constructor: ClassType<T>, config: Partial<T> | null, ...children: any[]): any;
|
||||
class Fragment extends Group {
|
||||
}
|
||||
}
|
||||
|
@@ -3,26 +3,47 @@ import { layoutConfig } from "./layoutconfig";
|
||||
export var jsx;
|
||||
(function (jsx) {
|
||||
function createElement(constructor, config, ...children) {
|
||||
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.isViewClass) {
|
||||
const e = new constructor();
|
||||
if (e instanceof Fragment) {
|
||||
return children;
|
||||
}
|
||||
if (Reflect.has(e, "innerElement")) {
|
||||
Reflect.set(e, "innerElement", children, e);
|
||||
e.layoutConfig = layoutConfig().fit();
|
||||
if (config) {
|
||||
e.apply(config);
|
||||
}
|
||||
else {
|
||||
throw new Error(`Do not support ${constructor.name} for ${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 ${constructor.name} for ${children}`);
|
||||
}
|
||||
}
|
||||
return e;
|
||||
}
|
||||
else {
|
||||
const f = constructor;
|
||||
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;
|
||||
}
|
||||
jsx.createElement = createElement;
|
||||
class Fragment extends Group {
|
||||
|
Reference in New Issue
Block a user