test context entity method success
This commit is contained in:
@@ -1,16 +1,35 @@
|
||||
import { jsObtainContext } from 'doric/src/runtime/sandbox'
|
||||
import { Panel } from 'doric'
|
||||
import { DoricPlugin } from "./DoricPlugin"
|
||||
|
||||
import { createContext } from "./DoricDriver"
|
||||
const doricContexts: Map<string, DoricContext> = new Map
|
||||
|
||||
let __contextId__ = 0
|
||||
function getContextId() {
|
||||
return `context_${__contextId__++}`
|
||||
}
|
||||
|
||||
export function getDoricContext(contextId: string) {
|
||||
return doricContexts.get(contextId)
|
||||
}
|
||||
|
||||
export class DoricContext {
|
||||
contextId: string
|
||||
contextId = getContextId()
|
||||
pluginInstances: Map<string, DoricPlugin> = new Map
|
||||
constructor(contextId: string) {
|
||||
this.contextId = contextId
|
||||
doricContexts.set(contextId, this)
|
||||
constructor(content: string) {
|
||||
createContext(this.contextId, content)
|
||||
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 { getDoricContext } from './DoricContext'
|
||||
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) {
|
||||
Reflect.set(window, name, value, window)
|
||||
@@ -38,7 +34,6 @@ ${content}
|
||||
},doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{}])`
|
||||
}
|
||||
|
||||
|
||||
function initDoric() {
|
||||
injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => {
|
||||
switch (type) {
|
||||
@@ -104,5 +99,8 @@ function initDoric() {
|
||||
})
|
||||
|
||||
}
|
||||
export function createContext(contextId: string, content: string) {
|
||||
loadJS(packageCreateContext(contextId, content))
|
||||
}
|
||||
|
||||
initDoric()
|
@@ -1,10 +1,11 @@
|
||||
import axios from 'axios'
|
||||
import { getContextId } from './DoricDriver'
|
||||
import { DoricContext } from './DoricContext'
|
||||
|
||||
|
||||
export class DoricElement extends HTMLElement {
|
||||
source: string
|
||||
alias: string
|
||||
context?: DoricContext
|
||||
constructor() {
|
||||
super()
|
||||
this.source = this.getAttribute('src') || ""
|
||||
@@ -15,11 +16,7 @@ export class DoricElement extends HTMLElement {
|
||||
}
|
||||
|
||||
load(content: string) {
|
||||
const script = document.createElement('script');
|
||||
const contextId = getContextId();
|
||||
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)
|
||||
this.context = new DoricContext(content)
|
||||
this.context.getEntityMethod('log')()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user