Entry add exports defination

This commit is contained in:
pengfei.zhou 2020-09-04 17:05:51 +08:00 committed by osborn
parent f14017281e
commit a211ac8acb
10 changed files with 126 additions and 65 deletions

View File

@ -1394,7 +1394,7 @@ var doric = (function (exports) {
} }
function jsObtainEntry(contextId) { function jsObtainEntry(contextId) {
var context = jsObtainContext(contextId); var context = jsObtainContext(contextId);
return function (constructor) { var exportFunc = function (constructor) {
var ret = /** @class */ (function (_super) { var ret = /** @class */ (function (_super) {
__extends(class_1, _super); __extends(class_1, _super);
function class_1() { function class_1() {
@ -1409,6 +1409,14 @@ var doric = (function (exports) {
} }
return ret; return ret;
}; };
return function (args) {
if (args instanceof Array) {
return exportFunc;
}
else {
return exportFunc(args);
}
};
} }
var global$1 = Function('return this')(); var global$1 = Function('return this')();
var __timerId__ = 0; var __timerId__ = 0;

View File

@ -1395,7 +1395,7 @@ var doric = (function (exports) {
} }
function jsObtainEntry(contextId) { function jsObtainEntry(contextId) {
const context = jsObtainContext(contextId); const context = jsObtainContext(contextId);
return (constructor) => { const exportFunc = (constructor) => {
const ret = class extends constructor { const ret = class extends constructor {
constructor() { constructor() {
super(...arguments); super(...arguments);
@ -1407,6 +1407,14 @@ var doric = (function (exports) {
} }
return ret; return ret;
}; };
return (args) => {
if (args instanceof Array) {
return exportFunc;
}
else {
return exportFunc(args);
}
};
} }
const global$1 = Function('return this')(); const global$1 = Function('return this')();
let __timerId__ = 0; let __timerId__ = 0;

View File

@ -1418,7 +1418,7 @@ function jsCallEntityMethod(contextId, methodName, args) {
} }
function jsObtainEntry(contextId) { function jsObtainEntry(contextId) {
const context = jsObtainContext(contextId); const context = jsObtainContext(contextId);
return (constructor) => { const exportFunc = (constructor) => {
const ret = class extends constructor { const ret = class extends constructor {
constructor() { constructor() {
super(...arguments); super(...arguments);
@ -1430,6 +1430,14 @@ function jsObtainEntry(contextId) {
} }
return ret; return ret;
}; };
return (args) => {
if (args instanceof Array) {
return exportFunc;
}
else {
return exportFunc(args);
}
};
} }
const global$1 = Function('return this')(); const global$1 = Function('return this')();
let __timerId__ = 0; let __timerId__ = 0;

103
doric-js/index.d.ts vendored
View File

@ -10,6 +10,8 @@ declare module 'doric' {
} }
declare module 'doric/lib/src/runtime/global' { declare module 'doric/lib/src/runtime/global' {
import { Panel } from "doric/lib/src/ui/panel";
import { ClassType } from "doric/lib/src/pattern/mvvm";
export type BridgeContext = { export type BridgeContext = {
/** /**
* The identify of current context * The identify of current context
@ -60,9 +62,8 @@ declare module 'doric/lib/src/runtime/global' {
deviceModel: string; deviceModel: string;
[index: string]: number | string | boolean | object | undefined; [index: string]: number | string | boolean | object | undefined;
}; };
function Entry(constructor: { function Entry(constructor: ClassType<Panel>): void;
new (...args: any[]): {}; function Entry(exports: ClassType<Panel>[]): (constructor: ClassType<Panel>) => void;
}): any;
} }
export {}; export {};
} }
@ -118,6 +119,54 @@ declare module 'doric/lib/src/pattern/index.pattern' {
export * from 'doric/lib/src/pattern/mvvm'; export * from 'doric/lib/src/pattern/mvvm';
} }
declare module 'doric/lib/src/ui/panel' {
import { View, Group } from "doric/lib/src/ui/view";
import { Root } from 'doric/lib/src/widget/layouts';
import { BridgeContext } from 'doric/lib/src/runtime/global';
export function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
export abstract class Panel {
context: BridgeContext;
onCreate(): void;
onDestroy(): void;
onShow(): void;
onHidden(): void;
abstract build(rootView: Group): void;
addHeadView(type: string, v: View): void;
allHeadViews(): IterableIterator<Map<string, View>>;
removeHeadView(type: string, v: View | string): void;
clearHeadViews(type: string): void;
getRootView(): Root;
getInitData(): object | undefined;
addOnRenderFinishedCallback(cb: () => void): void;
}
}
declare module 'doric/lib/src/pattern/mvvm' {
import { Group } from "doric/lib/src/ui/view";
import { Panel } from "doric/lib/src/ui/panel";
export abstract class ViewHolder {
abstract build(root: Group): void;
}
export type Setter<M> = (state: M) => void;
export abstract class ViewModel<M extends Object, V extends ViewHolder> {
constructor(obj: M, v: V);
getState(): M;
getViewHolder(): V;
updateState(setter: Setter<M>): void;
attach(view: Group): void;
abstract onAttached(state: M, vh: V): void;
abstract onBind(state: M, vh: V): void;
}
export type ClassType<T> = new (...args: any) => T;
export abstract class VMPanel<M extends Object, V extends ViewHolder> extends Panel {
abstract getViewModelClass(): ClassType<ViewModel<M, V>>;
abstract getState(): M;
abstract getViewHolderClass(): ClassType<V>;
getViewModel(): ViewModel<M, V> | undefined;
build(root: Group): void;
}
}
declare module 'doric/lib/src/ui/view' { declare module 'doric/lib/src/ui/view' {
import { Color, GradientColor } from "doric/lib/src/util/color"; import { Color, GradientColor } from "doric/lib/src/util/color";
import { Modeling, Model } from "doric/lib/src/util/types"; import { Modeling, Model } from "doric/lib/src/util/types";
@ -263,28 +312,6 @@ declare module 'doric/lib/src/ui/view' {
} }
} }
declare module 'doric/lib/src/ui/panel' {
import { View, Group } from "doric/lib/src/ui/view";
import { Root } from 'doric/lib/src/widget/layouts';
import { BridgeContext } from 'doric/lib/src/runtime/global';
export function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
export abstract class Panel {
context: BridgeContext;
onCreate(): void;
onDestroy(): void;
onShow(): void;
onHidden(): void;
abstract build(rootView: Group): void;
addHeadView(type: string, v: View): void;
allHeadViews(): IterableIterator<Map<string, View>>;
removeHeadView(type: string, v: View | string): void;
clearHeadViews(type: string): void;
getRootView(): Root;
getInitData(): object | undefined;
addOnRenderFinishedCallback(cb: () => void): void;
}
}
declare module 'doric/lib/src/ui/animation' { declare module 'doric/lib/src/ui/animation' {
import { Modeling, Model } from "doric/lib/src/util/types"; import { Modeling, Model } from "doric/lib/src/util/types";
export type AnimatedKey = "translationX" | "translationY" | "scaleX" | "scaleY" | "rotation" | "pivotX" | "pivotY" | "rotationX" | "rotationY"; export type AnimatedKey = "translationX" | "translationY" | "scaleX" | "scaleY" | "rotation" | "pivotX" | "pivotY" | "rotationX" | "rotationY";
@ -1323,32 +1350,6 @@ declare module 'doric/lib/src/pattern/provider' {
} }
} }
declare module 'doric/lib/src/pattern/mvvm' {
import { Group } from "doric/lib/src/ui/view";
import { Panel } from "doric/lib/src/ui/panel";
export abstract class ViewHolder {
abstract build(root: Group): void;
}
export type Setter<M> = (state: M) => void;
export abstract class ViewModel<M extends Object, V extends ViewHolder> {
constructor(obj: M, v: V);
getState(): M;
getViewHolder(): V;
updateState(setter: Setter<M>): void;
attach(view: Group): void;
abstract onAttached(state: M, vh: V): void;
abstract onBind(state: M, vh: V): void;
}
export type ClassType<T> = new (...args: any) => T;
export abstract class VMPanel<M extends Object, V extends ViewHolder> extends Panel {
abstract getViewModelClass(): ClassType<ViewModel<M, V>>;
abstract getState(): M;
abstract getViewHolderClass(): ClassType<V>;
getViewModel(): ViewModel<M, V> | undefined;
build(root: Group): void;
}
}
declare module '*.png' { declare module '*.png' {
const value: any; const value: any;
export default value; export default value;

View File

@ -1,3 +1,5 @@
import { Panel } from "../ui/panel";
import { ClassType } from "../pattern/mvvm";
export declare type BridgeContext = { export declare type BridgeContext = {
/** /**
* The identify of current context * The identify of current context
@ -48,8 +50,7 @@ declare global {
deviceModel: string; deviceModel: string;
[index: string]: number | string | boolean | object | undefined; [index: string]: number | string | boolean | object | undefined;
}; };
function Entry(constructor: { function Entry(constructor: ClassType<Panel>): void;
new (...args: any[]): {}; function Entry(exports: ClassType<Panel>[]): (constructor: ClassType<Panel>) => void;
}): any;
} }
export {}; export {};

View File

@ -21,9 +21,15 @@ export declare function jsReleaseContext(id: string): void;
export declare function __require__(name: string): any; export declare function __require__(name: string): any;
export declare function jsRegisterModule(name: string, moduleObject: any): void; export declare function jsRegisterModule(name: string, moduleObject: any): void;
export declare function jsCallEntityMethod(contextId: string, methodName: string, args?: any): any; export declare function jsCallEntityMethod(contextId: string, methodName: string, args?: any): any;
export declare function jsObtainEntry(contextId: string): <T extends new (...args: any[]) => {}>(constructor: T) => { declare type ClassType<T> = new (...args: any) => T;
new (...args: any[]): { export declare function jsObtainEntry(contextId: string): (args: ClassType<object> | ClassType<object>[]) => ((constructor: ClassType<object>) => {
new (...args: any): {
context: Context | undefined; context: Context | undefined;
}; };
} & T; }) | {
new (...args: any): {
context: Context | undefined;
};
};
export declare function jsCallbackTimer(timerId: number): void; export declare function jsCallbackTimer(timerId: number): void;
export {};

View File

@ -213,7 +213,7 @@ export function jsCallEntityMethod(contextId, methodName, args) {
} }
export function jsObtainEntry(contextId) { export function jsObtainEntry(contextId) {
const context = jsObtainContext(contextId); const context = jsObtainContext(contextId);
return (constructor) => { const exportFunc = (constructor) => {
const ret = class extends constructor { const ret = class extends constructor {
constructor() { constructor() {
super(...arguments); super(...arguments);
@ -225,6 +225,14 @@ export function jsObtainEntry(contextId) {
} }
return ret; return ret;
}; };
return (args) => {
if (args instanceof Array) {
return exportFunc;
}
else {
return exportFunc(args);
}
};
} }
const global = Function('return this')(); const global = Function('return this')();
let __timerId__ = 0; let __timerId__ = 0;

View File

@ -1,3 +1,6 @@
import { Panel } from "../ui/panel"
import { ClassType } from "../pattern/mvvm"
/* /*
* Copyright [2019] [Doric.Pub] * Copyright [2019] [Doric.Pub]
* *
@ -74,6 +77,9 @@ declare global {
deviceModel: string, deviceModel: string,
[index: string]: number | string | boolean | object | undefined [index: string]: number | string | boolean | object | undefined
} }
function Entry(constructor: { new(...args: any[]): {} }): any
function Entry(constructor: ClassType<Panel>): void
function Entry(exports: ClassType<Panel>[]): (constructor: ClassType<Panel>) => void;
} }
export { } export { }

View File

@ -233,10 +233,11 @@ export function jsCallEntityMethod(contextId: string, methodName: string, args?:
loge(`Cannot find method for context id:${contextId},method name is:${methodName}`) loge(`Cannot find method for context id:${contextId},method name is:${methodName}`)
} }
} }
type ClassType<T> = new (...args: any) => T
export function jsObtainEntry(contextId: string) { export function jsObtainEntry(contextId: string) {
const context = jsObtainContext(contextId) const context = jsObtainContext(contextId)
return <T extends { new(...args: any[]): {} }>(constructor: T) => { const exportFunc = (constructor: ClassType<object>) => {
const ret = class extends constructor { const ret = class extends constructor {
context = context context = context
} }
@ -245,6 +246,13 @@ export function jsObtainEntry(contextId: string) {
} }
return ret return ret
} }
return (args: ClassType<object> | ClassType<object>[]) => {
if (args instanceof Array) {
return exportFunc
} else {
return exportFunc(args)
}
}
} }

View File

@ -260,10 +260,11 @@ export function jsCallEntityMethod(contextId: string, methodName: string, args?:
loge(`Cannot find method for context id:${contextId},method name is:${methodName}`) loge(`Cannot find method for context id:${contextId},method name is:${methodName}`)
} }
} }
type ClassType<T> = new (...args: any) => T
export function jsObtainEntry(contextId: string) { export function jsObtainEntry(contextId: string) {
const context = jsObtainContext(contextId) const context = jsObtainContext(contextId)
return <T extends { new(...args: any[]): {} }>(constructor: T) => { const exportFunc = (constructor: ClassType<object>) => {
const ret = class extends constructor { const ret = class extends constructor {
context = context context = context
} }
@ -272,8 +273,14 @@ export function jsObtainEntry(contextId: string) {
} }
return ret return ret
} }
return (args: ClassType<object> | ClassType<object>[]) => {
if (args instanceof Array) {
return exportFunc
} else {
return exportFunc(args)
}
}
} }
const global = Function('return this')() const global = Function('return this')()
let __timerId__ = 0 let __timerId__ = 0