test context entity method success
This commit is contained in:
parent
c2b8abeadb
commit
1b65fd5ba0
4
dist/Counter.js
vendored
4
dist/Counter.js
vendored
@ -12,6 +12,10 @@ var __metadata = (undefined && undefined.__metadata) || function (k, v) {
|
|||||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||||
};
|
};
|
||||||
class CounterView extends doric.ViewHolder {
|
class CounterView extends doric.ViewHolder {
|
||||||
|
test() {
|
||||||
|
console.log('Invoke Success')
|
||||||
|
}
|
||||||
|
|
||||||
build(root) {
|
build(root) {
|
||||||
root.addChild(doric.vlayout([
|
root.addChild(doric.vlayout([
|
||||||
doric.text({
|
doric.text({
|
||||||
|
138
dist/index.js
vendored
138
dist/index.js
vendored
@ -1478,7 +1478,7 @@ var doric = (function (exports) {
|
|||||||
/**--------SandBox--------*/
|
/**--------SandBox--------*/
|
||||||
|
|
||||||
/**++++++++Lib++++++++*/
|
/**++++++++Lib++++++++*/
|
||||||
Reflect.apply(doric.jsRegisterModule,this,[doric,Reflect.apply(function(__module){(function(module,exports,require){
|
Reflect.apply(doric.jsRegisterModule,this,["doric",Reflect.apply(function(__module){(function(module,exports,require){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
Object.defineProperty(exports, '__esModule', { value: true });
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
@ -3537,14 +3537,134 @@ return __module.exports;
|
|||||||
|
|
||||||
axios = axios && axios.hasOwnProperty('default') ? axios['default'] : axios;
|
axios = axios && axios.hasOwnProperty('default') ? axios['default'] : axios;
|
||||||
|
|
||||||
let contexId = 0;
|
const bundles = new Map;
|
||||||
function getContextId() {
|
const plugins = new Map;
|
||||||
return `${contexId++}`;
|
function acquireJSBundle(name) {
|
||||||
|
return bundles.get(name);
|
||||||
|
}
|
||||||
|
function acquirePlugin(name) {
|
||||||
|
return plugins.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
let __scriptId__ = 0;
|
||||||
|
function getScriptId() {
|
||||||
|
return `script_${__scriptId__++}`;
|
||||||
|
}
|
||||||
|
function injectGlobalObject(name, value) {
|
||||||
|
Reflect.set(window, name, value, window);
|
||||||
|
}
|
||||||
|
function loadJS(script) {
|
||||||
|
const scriptElement = document.createElement('script');
|
||||||
|
scriptElement.text = script;
|
||||||
|
scriptElement.id = getScriptId();
|
||||||
|
document.body.appendChild(scriptElement);
|
||||||
|
}
|
||||||
|
function packageModuleScript(name, content) {
|
||||||
|
return `Reflect.apply(doric.jsRegisterModule,this,[${name},Reflect.apply(function(__module){(function(module,exports,require){
|
||||||
|
${content}
|
||||||
|
})(__module,__module.exports,doric.__require__);
|
||||||
|
return __module.exports;},this,[{exports:{}}])])`;
|
||||||
|
}
|
||||||
|
function packageCreateContext(contextId, content) {
|
||||||
|
return `Reflect.apply(function(doric,context,Entry,require,exports){
|
||||||
|
${content}
|
||||||
|
},doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{}])`;
|
||||||
}
|
}
|
||||||
function initDoric() {
|
function initDoric() {
|
||||||
sandbox.jsCallReject('', '');
|
injectGlobalObject('nativeLog', (type, message) => {
|
||||||
|
switch (type) {
|
||||||
|
case 'd':
|
||||||
|
console.log(message);
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
console.warn(message);
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
console.error(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
injectGlobalObject('nativeRequire', (moduleName) => {
|
||||||
|
const bundle = acquireJSBundle(moduleName);
|
||||||
|
if (bundle === undefined || bundle.length === 0) {
|
||||||
|
console.log(`Cannot require JS Bundle :${moduleName}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
loadJS(packageModuleScript(moduleName, packageModuleScript(name, bundle)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
injectGlobalObject('nativeBridge', (contextId, namespace, method, callbackId, args) => {
|
||||||
|
const pluginClass = acquirePlugin(namespace);
|
||||||
|
const doricContext = getDoricContext(contextId);
|
||||||
|
if (pluginClass === undefined) {
|
||||||
|
console.error(`Cannot find Plugin:${namespace}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (doricContext === undefined) {
|
||||||
|
console.error(`Cannot find Doric Context:${contextId}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let plugin = doricContext.pluginInstances.get(namespace);
|
||||||
|
if (plugin === undefined) {
|
||||||
|
plugin = new pluginClass(doricContext);
|
||||||
|
doricContext.pluginInstances.set(namespace, plugin);
|
||||||
|
}
|
||||||
|
if (!Reflect.has(plugin, method)) {
|
||||||
|
console.error(`Cannot find Method:${method} in plugin ${namespace}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const pluginMethod = Reflect.get(plugin, method, plugin);
|
||||||
|
if (typeof pluginMethod !== 'function') {
|
||||||
|
console.error(`Plugin ${namespace}'s property ${method}'s type is ${typeof pluginMethod} not function,`);
|
||||||
|
}
|
||||||
|
const ret = Reflect.apply(pluginMethod, plugin, [args]);
|
||||||
|
if (ret instanceof Promise) {
|
||||||
|
ret.then(e => {
|
||||||
|
sandbox.jsCallResolve(contextId, callbackId, e);
|
||||||
|
}, e => {
|
||||||
|
sandbox.jsCallReject(contextId, callbackId, e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sandbox.jsCallResolve(contextId, callbackId, ret);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function createContext(contextId, content) {
|
||||||
|
loadJS(packageCreateContext(contextId, content));
|
||||||
}
|
}
|
||||||
initDoric();
|
initDoric();
|
||||||
|
|
||||||
|
const doricContexts = new Map;
|
||||||
|
let __contextId__ = 0;
|
||||||
|
function getContextId() {
|
||||||
|
return `context_${__contextId__++}`;
|
||||||
|
}
|
||||||
|
function getDoricContext(contextId) {
|
||||||
|
return doricContexts.get(contextId);
|
||||||
|
}
|
||||||
|
class DoricContext {
|
||||||
|
constructor(content) {
|
||||||
|
this.contextId = getContextId();
|
||||||
|
this.pluginInstances = new Map;
|
||||||
|
createContext(this.contextId, content);
|
||||||
|
doricContexts.set(this.contextId, this);
|
||||||
|
}
|
||||||
|
get context() {
|
||||||
|
return sandbox.jsObtainContext(this.contextId);
|
||||||
|
}
|
||||||
|
get panel() {
|
||||||
|
var _a;
|
||||||
|
return (_a = this.context) === null || _a === void 0 ? void 0 : _a.entity;
|
||||||
|
}
|
||||||
|
getEntityMethod(method) {
|
||||||
|
return Reflect.get(this.panel, method, this.panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class DoricElement extends HTMLElement {
|
class DoricElement extends HTMLElement {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -3555,12 +3675,8 @@ return __module.exports;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
load(content) {
|
load(content) {
|
||||||
const script = document.createElement('script');
|
this.context = new DoricContext(content);
|
||||||
const contextId = getContextId();
|
this.context.getEntityMethod('log')();
|
||||||
script.text = `Reflect.apply(function(doric,context,Entry,require,exports){
|
|
||||||
${content}
|
|
||||||
},doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{}]);`;
|
|
||||||
this.append(script);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
@ -14,7 +14,7 @@ ${sandboxBundle}
|
|||||||
/**--------SandBox--------*/
|
/**--------SandBox--------*/
|
||||||
|
|
||||||
/**++++++++Lib++++++++*/
|
/**++++++++Lib++++++++*/
|
||||||
Reflect.apply(doric.jsRegisterModule,this,[doric,Reflect.apply(function(__module){(function(module,exports,require){
|
Reflect.apply(doric.jsRegisterModule,this,["doric",Reflect.apply(function(__module){(function(module,exports,require){
|
||||||
${doricLibBundle}
|
${doricLibBundle}
|
||||||
})(__module,__module.exports,doric.__require__);
|
})(__module,__module.exports,doric.__require__);
|
||||||
return __module.exports;
|
return __module.exports;
|
||||||
|
@ -1,16 +1,35 @@
|
|||||||
|
import { jsObtainContext } from 'doric/src/runtime/sandbox'
|
||||||
|
import { Panel } from 'doric'
|
||||||
import { DoricPlugin } from "./DoricPlugin"
|
import { DoricPlugin } from "./DoricPlugin"
|
||||||
|
import { createContext } from "./DoricDriver"
|
||||||
const doricContexts: Map<string, DoricContext> = new Map
|
const doricContexts: Map<string, DoricContext> = new Map
|
||||||
|
|
||||||
|
let __contextId__ = 0
|
||||||
|
function getContextId() {
|
||||||
|
return `context_${__contextId__++}`
|
||||||
|
}
|
||||||
|
|
||||||
export function getDoricContext(contextId: string) {
|
export function getDoricContext(contextId: string) {
|
||||||
return doricContexts.get(contextId)
|
return doricContexts.get(contextId)
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DoricContext {
|
export class DoricContext {
|
||||||
contextId: string
|
contextId = getContextId()
|
||||||
pluginInstances: Map<string, DoricPlugin> = new Map
|
pluginInstances: Map<string, DoricPlugin> = new Map
|
||||||
constructor(contextId: string) {
|
constructor(content: string) {
|
||||||
this.contextId = contextId
|
createContext(this.contextId, content)
|
||||||
doricContexts.set(contextId, this)
|
doricContexts.set(this.contextId, this)
|
||||||
}
|
}
|
||||||
|
get context() {
|
||||||
|
return jsObtainContext(this.contextId)
|
||||||
|
}
|
||||||
|
|
||||||
|
get panel() {
|
||||||
|
return this.context?.entity as Panel
|
||||||
|
}
|
||||||
|
|
||||||
|
getEntityMethod(method: string) {
|
||||||
|
return Reflect.get(this.panel, method, this.panel) as Function
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { jsObtainContext, jsCallResolve, jsCallReject } from 'doric/src/runtime/sandbox'
|
import { jsCallResolve, jsCallReject } from 'doric/src/runtime/sandbox'
|
||||||
import { acquireJSBundle, acquirePlugin } from './DoricRegistry'
|
import { acquireJSBundle, acquirePlugin } from './DoricRegistry'
|
||||||
import { getDoricContext } from './DoricContext'
|
import { getDoricContext } from './DoricContext'
|
||||||
import { DoricPlugin } from './DoricPlugin'
|
import { DoricPlugin } from './DoricPlugin'
|
||||||
@ -9,10 +9,6 @@ function getScriptId() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let __contextId__ = 0
|
|
||||||
export function getContextId() {
|
|
||||||
return `context_${__contextId__++}`
|
|
||||||
}
|
|
||||||
|
|
||||||
export function injectGlobalObject(name: string, value: any) {
|
export function injectGlobalObject(name: string, value: any) {
|
||||||
Reflect.set(window, name, value, window)
|
Reflect.set(window, name, value, window)
|
||||||
@ -38,7 +34,6 @@ ${content}
|
|||||||
},doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{}])`
|
},doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{}])`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function initDoric() {
|
function initDoric() {
|
||||||
injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => {
|
injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -104,5 +99,8 @@ function initDoric() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
export function createContext(contextId: string, content: string) {
|
||||||
|
loadJS(packageCreateContext(contextId, content))
|
||||||
|
}
|
||||||
|
|
||||||
initDoric()
|
initDoric()
|
@ -1,10 +1,11 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { getContextId } from './DoricDriver'
|
import { DoricContext } from './DoricContext'
|
||||||
|
|
||||||
|
|
||||||
export class DoricElement extends HTMLElement {
|
export class DoricElement extends HTMLElement {
|
||||||
source: string
|
source: string
|
||||||
alias: string
|
alias: string
|
||||||
|
context?: DoricContext
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.source = this.getAttribute('src') || ""
|
this.source = this.getAttribute('src') || ""
|
||||||
@ -15,11 +16,7 @@ export class DoricElement extends HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
load(content: string) {
|
load(content: string) {
|
||||||
const script = document.createElement('script');
|
this.context = new DoricContext(content)
|
||||||
const contextId = getContextId();
|
this.context.getEntityMethod('log')()
|
||||||
script.text = `Reflect.apply(function(doric,context,Entry,require,exports){
|
|
||||||
${content}
|
|
||||||
},doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{}]);`
|
|
||||||
this.append(script)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user