From a211ac8acb5a40aae82e6d46de9f26a58bd13ede Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 4 Sep 2020 17:05:51 +0800 Subject: [PATCH] Entry add exports defination --- doric-js/bundle/doric-sandbox.es5.js | 10 ++- doric-js/bundle/doric-sandbox.js | 10 ++- doric-js/bundle/doric-vm.js | 10 ++- doric-js/index.d.ts | 103 +++++++++++++------------- doric-js/lib/src/runtime/global.d.ts | 7 +- doric-js/lib/src/runtime/sandbox.d.ts | 12 ++- doric-js/lib/src/runtime/sandbox.js | 10 ++- doric-js/src/runtime/global.ts | 8 +- doric-js/src/runtime/sandbox.es5.ts | 10 ++- doric-js/src/runtime/sandbox.ts | 11 ++- 10 files changed, 126 insertions(+), 65 deletions(-) diff --git a/doric-js/bundle/doric-sandbox.es5.js b/doric-js/bundle/doric-sandbox.es5.js index ff0aabda..d172ad9d 100644 --- a/doric-js/bundle/doric-sandbox.es5.js +++ b/doric-js/bundle/doric-sandbox.es5.js @@ -1394,7 +1394,7 @@ var doric = (function (exports) { } function jsObtainEntry(contextId) { var context = jsObtainContext(contextId); - return function (constructor) { + var exportFunc = function (constructor) { var ret = /** @class */ (function (_super) { __extends(class_1, _super); function class_1() { @@ -1409,6 +1409,14 @@ var doric = (function (exports) { } return ret; }; + return function (args) { + if (args instanceof Array) { + return exportFunc; + } + else { + return exportFunc(args); + } + }; } var global$1 = Function('return this')(); var __timerId__ = 0; diff --git a/doric-js/bundle/doric-sandbox.js b/doric-js/bundle/doric-sandbox.js index 29c492f9..333608cc 100644 --- a/doric-js/bundle/doric-sandbox.js +++ b/doric-js/bundle/doric-sandbox.js @@ -1395,7 +1395,7 @@ var doric = (function (exports) { } function jsObtainEntry(contextId) { const context = jsObtainContext(contextId); - return (constructor) => { + const exportFunc = (constructor) => { const ret = class extends constructor { constructor() { super(...arguments); @@ -1407,6 +1407,14 @@ var doric = (function (exports) { } return ret; }; + return (args) => { + if (args instanceof Array) { + return exportFunc; + } + else { + return exportFunc(args); + } + }; } const global$1 = Function('return this')(); let __timerId__ = 0; diff --git a/doric-js/bundle/doric-vm.js b/doric-js/bundle/doric-vm.js index 91edeaad..89a73e04 100644 --- a/doric-js/bundle/doric-vm.js +++ b/doric-js/bundle/doric-vm.js @@ -1418,7 +1418,7 @@ function jsCallEntityMethod(contextId, methodName, args) { } function jsObtainEntry(contextId) { const context = jsObtainContext(contextId); - return (constructor) => { + const exportFunc = (constructor) => { const ret = class extends constructor { constructor() { super(...arguments); @@ -1430,6 +1430,14 @@ function jsObtainEntry(contextId) { } return ret; }; + return (args) => { + if (args instanceof Array) { + return exportFunc; + } + else { + return exportFunc(args); + } + }; } const global$1 = Function('return this')(); let __timerId__ = 0; diff --git a/doric-js/index.d.ts b/doric-js/index.d.ts index 01f087e4..c2fa5a71 100644 --- a/doric-js/index.d.ts +++ b/doric-js/index.d.ts @@ -10,6 +10,8 @@ declare module 'doric' { } 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 = { /** * The identify of current context @@ -60,9 +62,8 @@ declare module 'doric/lib/src/runtime/global' { deviceModel: string; [index: string]: number | string | boolean | object | undefined; }; - function Entry(constructor: { - new (...args: any[]): {}; - }): any; + function Entry(constructor: ClassType): void; + function Entry(exports: ClassType[]): (constructor: ClassType) => void; } export {}; } @@ -118,6 +119,54 @@ declare module 'doric/lib/src/pattern/index.pattern' { 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>; + 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 = (state: M) => void; + export abstract class ViewModel { + constructor(obj: M, v: V); + getState(): M; + getViewHolder(): V; + updateState(setter: Setter): void; + attach(view: Group): void; + abstract onAttached(state: M, vh: V): void; + abstract onBind(state: M, vh: V): void; + } + export type ClassType = new (...args: any) => T; + export abstract class VMPanel extends Panel { + abstract getViewModelClass(): ClassType>; + abstract getState(): M; + abstract getViewHolderClass(): ClassType; + getViewModel(): ViewModel | undefined; + build(root: Group): void; + } +} + declare module 'doric/lib/src/ui/view' { import { Color, GradientColor } from "doric/lib/src/util/color"; 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>; - 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' { import { Modeling, Model } from "doric/lib/src/util/types"; 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 = (state: M) => void; - export abstract class ViewModel { - constructor(obj: M, v: V); - getState(): M; - getViewHolder(): V; - updateState(setter: Setter): void; - attach(view: Group): void; - abstract onAttached(state: M, vh: V): void; - abstract onBind(state: M, vh: V): void; - } - export type ClassType = new (...args: any) => T; - export abstract class VMPanel extends Panel { - abstract getViewModelClass(): ClassType>; - abstract getState(): M; - abstract getViewHolderClass(): ClassType; - getViewModel(): ViewModel | undefined; - build(root: Group): void; - } -} - declare module '*.png' { const value: any; export default value; diff --git a/doric-js/lib/src/runtime/global.d.ts b/doric-js/lib/src/runtime/global.d.ts index f29aaec8..c8ae7f31 100644 --- a/doric-js/lib/src/runtime/global.d.ts +++ b/doric-js/lib/src/runtime/global.d.ts @@ -1,3 +1,5 @@ +import { Panel } from "../ui/panel"; +import { ClassType } from "../pattern/mvvm"; export declare type BridgeContext = { /** * The identify of current context @@ -48,8 +50,7 @@ declare global { deviceModel: string; [index: string]: number | string | boolean | object | undefined; }; - function Entry(constructor: { - new (...args: any[]): {}; - }): any; + function Entry(constructor: ClassType): void; + function Entry(exports: ClassType[]): (constructor: ClassType) => void; } export {}; diff --git a/doric-js/lib/src/runtime/sandbox.d.ts b/doric-js/lib/src/runtime/sandbox.d.ts index 14c28c28..b231fd2b 100644 --- a/doric-js/lib/src/runtime/sandbox.d.ts +++ b/doric-js/lib/src/runtime/sandbox.d.ts @@ -21,9 +21,15 @@ export declare function jsReleaseContext(id: string): void; export declare function __require__(name: string): any; export declare function jsRegisterModule(name: string, moduleObject: any): void; export declare function jsCallEntityMethod(contextId: string, methodName: string, args?: any): any; -export declare function jsObtainEntry(contextId: string): {}>(constructor: T) => { - new (...args: any[]): { +declare type ClassType = new (...args: any) => T; +export declare function jsObtainEntry(contextId: string): (args: ClassType | ClassType[]) => ((constructor: ClassType) => { + new (...args: any): { context: Context | undefined; }; -} & T; +}) | { + new (...args: any): { + context: Context | undefined; + }; +}; export declare function jsCallbackTimer(timerId: number): void; +export {}; diff --git a/doric-js/lib/src/runtime/sandbox.js b/doric-js/lib/src/runtime/sandbox.js index 332a9348..d018c53a 100644 --- a/doric-js/lib/src/runtime/sandbox.js +++ b/doric-js/lib/src/runtime/sandbox.js @@ -213,7 +213,7 @@ export function jsCallEntityMethod(contextId, methodName, args) { } export function jsObtainEntry(contextId) { const context = jsObtainContext(contextId); - return (constructor) => { + const exportFunc = (constructor) => { const ret = class extends constructor { constructor() { super(...arguments); @@ -225,6 +225,14 @@ export function jsObtainEntry(contextId) { } return ret; }; + return (args) => { + if (args instanceof Array) { + return exportFunc; + } + else { + return exportFunc(args); + } + }; } const global = Function('return this')(); let __timerId__ = 0; diff --git a/doric-js/src/runtime/global.ts b/doric-js/src/runtime/global.ts index 00170254..8cb42a9a 100644 --- a/doric-js/src/runtime/global.ts +++ b/doric-js/src/runtime/global.ts @@ -1,3 +1,6 @@ +import { Panel } from "../ui/panel" +import { ClassType } from "../pattern/mvvm" + /* * Copyright [2019] [Doric.Pub] * @@ -74,6 +77,9 @@ declare global { deviceModel: string, [index: string]: number | string | boolean | object | undefined } - function Entry(constructor: { new(...args: any[]): {} }): any + + function Entry(constructor: ClassType): void + + function Entry(exports: ClassType[]): (constructor: ClassType) => void; } export { } \ No newline at end of file diff --git a/doric-js/src/runtime/sandbox.es5.ts b/doric-js/src/runtime/sandbox.es5.ts index 69f47c64..8e915afd 100644 --- a/doric-js/src/runtime/sandbox.es5.ts +++ b/doric-js/src/runtime/sandbox.es5.ts @@ -233,10 +233,11 @@ export function jsCallEntityMethod(contextId: string, methodName: string, args?: loge(`Cannot find method for context id:${contextId},method name is:${methodName}`) } } +type ClassType = new (...args: any) => T export function jsObtainEntry(contextId: string) { const context = jsObtainContext(contextId) - return (constructor: T) => { + const exportFunc = (constructor: ClassType) => { const ret = class extends constructor { context = context } @@ -245,6 +246,13 @@ export function jsObtainEntry(contextId: string) { } return ret } + return (args: ClassType | ClassType[]) => { + if (args instanceof Array) { + return exportFunc + } else { + return exportFunc(args) + } + } } diff --git a/doric-js/src/runtime/sandbox.ts b/doric-js/src/runtime/sandbox.ts index 36e54194..aa3ebb6a 100644 --- a/doric-js/src/runtime/sandbox.ts +++ b/doric-js/src/runtime/sandbox.ts @@ -260,10 +260,11 @@ export function jsCallEntityMethod(contextId: string, methodName: string, args?: loge(`Cannot find method for context id:${contextId},method name is:${methodName}`) } } +type ClassType = new (...args: any) => T export function jsObtainEntry(contextId: string) { const context = jsObtainContext(contextId) - return (constructor: T) => { + const exportFunc = (constructor: ClassType) => { const ret = class extends constructor { context = context } @@ -272,9 +273,15 @@ export function jsObtainEntry(contextId: string) { } return ret } + return (args: ClassType | ClassType[]) => { + if (args instanceof Array) { + return exportFunc + } else { + return exportFunc(args) + } + } } - const global = Function('return this')() let __timerId__ = 0