Android support internal class
This commit is contained in:
4
doric-js/lib/src/native/navigator.d.ts
vendored
4
doric-js/lib/src/native/navigator.d.ts
vendored
@@ -1,6 +1,8 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { ClassType } from "../pattern/mvvm";
|
||||
import { Panel } from "../ui/panel";
|
||||
export declare function navigator(context: BridgeContext): {
|
||||
push: (source: string, config?: {
|
||||
push: (source: string | ClassType<Panel>, config?: {
|
||||
alias?: string | undefined;
|
||||
animated?: boolean | undefined;
|
||||
extra?: object | undefined;
|
||||
|
@@ -2,6 +2,9 @@ export function navigator(context) {
|
||||
const moduleName = "navigator";
|
||||
return {
|
||||
push: (source, config) => {
|
||||
if (typeof source === 'function') {
|
||||
source = `_internal_://export?class=${encodeURIComponent(source.name)}&context=${context.id}`;
|
||||
}
|
||||
if (config && config.extra) {
|
||||
config.extra = JSON.stringify(config.extra);
|
||||
}
|
||||
|
3
doric-js/lib/src/runtime/sandbox.d.ts
vendored
3
doric-js/lib/src/runtime/sandbox.d.ts
vendored
@@ -8,6 +8,7 @@ export declare class Context {
|
||||
resolve: Function;
|
||||
reject: Function;
|
||||
}>;
|
||||
classes: Map<string, ClassType<object>>;
|
||||
hookBeforeNativeCall(): void;
|
||||
hookAfterNativeCall(): void;
|
||||
constructor(id: string);
|
||||
@@ -22,7 +23,7 @@ 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;
|
||||
declare type ClassType<T> = new (...args: any) => T;
|
||||
export declare function jsObtainEntry(contextId: string): (args: ClassType<object> | ClassType<object>[]) => ((constructor: ClassType<object>) => {
|
||||
export declare function jsObtainEntry(contextId: string): () => ((constructor: ClassType<object>) => {
|
||||
new (...args: any): {
|
||||
context: Context | undefined;
|
||||
};
|
||||
|
@@ -74,6 +74,7 @@ export function jsCallReject(contextId, callbackId, args) {
|
||||
export class Context {
|
||||
constructor(id) {
|
||||
this.callbacks = new Map;
|
||||
this.classes = new Map;
|
||||
this.id = id;
|
||||
return new Proxy(this, {
|
||||
get: (target, p) => {
|
||||
@@ -214,23 +215,50 @@ export function jsCallEntityMethod(contextId, methodName, args) {
|
||||
export function jsObtainEntry(contextId) {
|
||||
const context = jsObtainContext(contextId);
|
||||
const exportFunc = (constructor) => {
|
||||
var _a;
|
||||
(_a = context === null || context === void 0 ? void 0 : context.classes) === null || _a === void 0 ? void 0 : _a.set(constructor.name, constructor);
|
||||
const ret = class extends constructor {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.context = context;
|
||||
}
|
||||
};
|
||||
if (context) {
|
||||
context.register(new ret);
|
||||
}
|
||||
context === null || context === void 0 ? void 0 : context.register(new ret);
|
||||
return ret;
|
||||
};
|
||||
return (args) => {
|
||||
if (args instanceof Array) {
|
||||
return exportFunc;
|
||||
return function () {
|
||||
if (arguments.length === 1) {
|
||||
const args = arguments[0];
|
||||
if (args instanceof Array) {
|
||||
args.forEach(clz => {
|
||||
var _a;
|
||||
(_a = context === null || context === void 0 ? void 0 : context.classes) === null || _a === void 0 ? void 0 : _a.set(clz.name, clz);
|
||||
});
|
||||
return exportFunc;
|
||||
}
|
||||
else {
|
||||
return exportFunc(args);
|
||||
}
|
||||
}
|
||||
else if (arguments.length === 2) {
|
||||
const srcContextId = arguments[0];
|
||||
const className = arguments[1];
|
||||
const srcContext = gContexts.get(srcContextId);
|
||||
if (srcContext) {
|
||||
const clz = srcContext.classes.get(className);
|
||||
if (clz) {
|
||||
return exportFunc(clz);
|
||||
}
|
||||
else {
|
||||
throw new Error(`Cannot find class:${className} in context:${srcContextId}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error(`Cannot find context for ${srcContextId}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return exportFunc(args);
|
||||
throw new Error(`Entry arguments error:${arguments}`);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user