invoke shaderplugin success

This commit is contained in:
pengfei.zhou 2019-12-19 13:34:56 +08:00
parent 1b65fd5ba0
commit 5854d29b93
8 changed files with 65 additions and 22 deletions

4
dist/Counter.js vendored
View File

@ -12,10 +12,6 @@ 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({

40
dist/index.js vendored
View File

@ -3537,14 +3537,30 @@ return __module.exports;
axios = axios && axios.hasOwnProperty('default') ? axios['default'] : axios; axios = axios && axios.hasOwnProperty('default') ? axios['default'] : axios;
class DoricPlugin {
constructor(context) {
this.context = context;
}
}
class ShaderPlugin extends DoricPlugin {
render(ret) {
console.log('render', ret);
}
}
const bundles = new Map; const bundles = new Map;
const plugins = new Map; const plugins = new Map;
function acquireJSBundle(name) { function acquireJSBundle(name) {
return bundles.get(name); return bundles.get(name);
} }
function registerPlugin(name, plugin) {
plugins.set(name, plugin);
}
function acquirePlugin(name) { function acquirePlugin(name) {
return plugins.get(name); return plugins.get(name);
} }
registerPlugin('shader', ShaderPlugin);
let __scriptId__ = 0; let __scriptId__ = 0;
function getScriptId() { function getScriptId() {
@ -3571,6 +3587,7 @@ ${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("nativeEmpty", () => undefined);
injectGlobalObject('nativeLog', (type, message) => { injectGlobalObject('nativeLog', (type, message) => {
switch (type) { switch (type) {
case 'd': case 'd':
@ -3627,7 +3644,7 @@ ${content}
sandbox.jsCallReject(contextId, callbackId, e); sandbox.jsCallReject(contextId, callbackId, e);
}); });
} }
else { else if (ret !== undefined) {
sandbox.jsCallResolve(contextId, callbackId, ret); sandbox.jsCallResolve(contextId, callbackId, ret);
} }
return true; return true;
@ -3653,15 +3670,19 @@ ${content}
createContext(this.contextId, content); createContext(this.contextId, content);
doricContexts.set(this.contextId, this); doricContexts.set(this.contextId, this);
} }
get context() {
return sandbox.jsObtainContext(this.contextId);
}
get panel() { get panel() {
var _a; var _a;
return (_a = this.context) === null || _a === void 0 ? void 0 : _a.entity; return (_a = sandbox.jsObtainContext(this.contextId)) === null || _a === void 0 ? void 0 : _a.entity;
} }
getEntityMethod(method) { invokeEntityMethod(method, ...otherArgs) {
return Reflect.get(this.panel, method, this.panel); const argumentsList = [this.contextId];
for (let i = 0; i < arguments.length; i++) {
argumentsList.push(arguments[i]);
}
Reflect.apply(sandbox.jsCallEntityMethod, this.panel, argumentsList);
}
init(frame, extra) {
this.invokeEntityMethod("__init__", frame, extra ? JSON.stringify(extra) : undefined);
} }
} }
@ -3676,7 +3697,10 @@ ${content}
} }
load(content) { load(content) {
this.context = new DoricContext(content); this.context = new DoricContext(content);
this.context.getEntityMethod('log')(); this.context.init({
width: 100,
height: 100
});
} }
} }

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
import { jsObtainContext } from 'doric/src/runtime/sandbox' import { jsObtainContext, jsCallEntityMethod } from 'doric/src/runtime/sandbox'
import { Panel } from 'doric' import { Panel } from 'doric'
import { DoricPlugin } from "./DoricPlugin" import { DoricPlugin } from "./DoricPlugin"
import { createContext } from "./DoricDriver" import { createContext } from "./DoricDriver"
@ -20,16 +20,24 @@ export class DoricContext {
createContext(this.contextId, content) createContext(this.contextId, content)
doricContexts.set(this.contextId, this) doricContexts.set(this.contextId, this)
} }
get context() {
return jsObtainContext(this.contextId)
}
get panel() { get panel() {
return this.context?.entity as Panel return jsObtainContext(this.contextId)?.entity as Panel
} }
getEntityMethod(method: string) { invokeEntityMethod(method: string, ...otherArgs: any) {
return Reflect.get(this.panel, method, this.panel) as Function const argumentsList: any = [this.contextId]
for (let i = 0; i < arguments.length; i++) {
argumentsList.push(arguments[i])
}
Reflect.apply(jsCallEntityMethod, this.panel, argumentsList)
}
init(frame: {
width: number,
height: number,
}, extra?: object) {
this.invokeEntityMethod("__init__", frame, extra ? JSON.stringify(extra) : undefined)
} }
} }

View File

@ -35,6 +35,8 @@ ${content}
} }
function initDoric() { function initDoric() {
injectGlobalObject("nativeEmpty", () => undefined)
injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => { injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => {
switch (type) { switch (type) {
case 'd': case 'd':
@ -92,7 +94,7 @@ function initDoric() {
e => { e => {
jsCallReject(contextId, callbackId, e) jsCallReject(contextId, callbackId, e)
}) })
} else { } else if (ret !== undefined) {
jsCallResolve(contextId, callbackId, ret) jsCallResolve(contextId, callbackId, ret)
} }
return true return true

View File

@ -17,6 +17,9 @@ export class DoricElement extends HTMLElement {
load(content: string) { load(content: string) {
this.context = new DoricContext(content) this.context = new DoricContext(content)
this.context.getEntityMethod('log')() this.context.init({
width: 100,
height: 100
})
} }
} }

View File

@ -1,4 +1,5 @@
import { DoricPluginClass } from "./DoricPlugin" import { DoricPluginClass } from "./DoricPlugin"
import { ShaderPlugin } from "./plugins/ShaderPlugin"
const bundles: Map<string, string> = new Map const bundles: Map<string, string> = new Map
@ -20,3 +21,5 @@ export function registerPlugin(name: string, plugin: DoricPluginClass) {
export function acquirePlugin(name: string) { export function acquirePlugin(name: string) {
return plugins.get(name) return plugins.get(name)
} }
registerPlugin('shader', ShaderPlugin)

View File

@ -0,0 +1,7 @@
import { DoricPlugin } from "../DoricPlugin";
export class ShaderPlugin extends DoricPlugin {
render(ret: any) {
console.log('render', ret)
}
}