Optimize unify panel hook after code

This commit is contained in:
pengfei.zhou 2021-09-16 12:52:02 +08:00 committed by osborn
parent dd4e8db3ad
commit 6046bf6163
14 changed files with 184 additions and 411 deletions

View File

@ -1275,138 +1275,59 @@ var Panel = /** @class */ (function () {
return this.context.callNative("shader", "render", model); return this.context.callNative("shader", "render", model);
}; };
Panel.prototype.hookBeforeNativeCall = function () { Panel.prototype.hookBeforeNativeCall = function () {
var e_2, _a, e_3, _b;
if (Environment.platform !== 'web') {
this.__root__.clean();
try {
for (var _c = __values$3(this.headviews.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
var map = _d.value;
try {
for (var _e = (e_3 = void 0, __values$3(map.values())), _f = _e.next(); !_f.done; _f = _e.next()) {
var v = _f.value;
v.clean();
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) { _b.call(_e); }
}
finally { if (e_3) { throw e_3.error; } }
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) { _a.call(_c); }
}
finally { if (e_2) { throw e_2.error; } }
}
}
}; };
Panel.prototype.hookAfterNativeCall = function () { Panel.prototype.hookAfterNativeCall = function () {
var e_4, _a, e_5, _b; var e_2, _a, e_3, _b;
var _this = this; var _this = this;
if (this.destroyed) { if (this.destroyed) {
return; return;
} }
var promises = []; var promises = [];
if (Environment.platform !== 'web') { if (this.__root__.isDirty()) {
//Here insert a native call to ensure the promise is resolved done. var model = this.__root__.toModel();
//nativeEmpty() promises.push(this.nativeRender(model));
if (this.__root__.isDirty()) { this.__root__.clean();
var model = this.__root__.toModel();
promises.push(this.nativeRender(model));
}
try {
for (var _c = __values$3(this.headviews.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
var map = _d.value;
try {
for (var _e = (e_5 = void 0, __values$3(map.values())), _f = _e.next(); !_f.done; _f = _e.next()) {
var v = _f.value;
if (v.isDirty()) {
var model = v.toModel();
promises.push(this.nativeRender(model));
}
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) { _b.call(_e); }
}
finally { if (e_5) { throw e_5.error; } }
}
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) { _a.call(_c); }
}
finally { if (e_4) { throw e_4.error; } }
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(function (_) {
});
}
else {
this.__rendering__ = true;
Promise.all(promises).then(function (_) {
_this.__rendering__ = false;
_this.onRenderFinished();
});
}
} }
else { try {
if (this.__rendering__) { for (var _c = __values$3(this.headviews.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
//skip var map = _d.value;
return;
}
this.__rendering__ = true;
Function("return this")().setTimeout(function () {
var e_6, _a, e_7, _b;
if (_this.__root__.isDirty()) {
var model = _this.__root__.toModel();
promises.push(_this.nativeRender(model));
_this.__root__.clean();
}
try { try {
for (var _c = __values$3(_this.headviews.values()), _d = _c.next(); !_d.done; _d = _c.next()) { for (var _e = (e_3 = void 0, __values$3(map.values())), _f = _e.next(); !_f.done; _f = _e.next()) {
var map = _d.value; var v = _f.value;
try { if (v.isDirty()) {
for (var _e = (e_7 = void 0, __values$3(map.values())), _f = _e.next(); !_f.done; _f = _e.next()) { var model = v.toModel();
var v = _f.value; promises.push(this.nativeRender(model));
if (v.isDirty()) { v.clean();
var model = v.toModel();
promises.push(_this.nativeRender(model));
v.clean();
}
}
}
catch (e_7_1) { e_7 = { error: e_7_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) { _b.call(_e); }
}
finally { if (e_7) { throw e_7.error; } }
} }
} }
} }
catch (e_6_1) { e_6 = { error: e_6_1 }; } catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally { finally {
try { try {
if (_d && !_d.done && (_a = _c.return)) { _a.call(_c); } if (_f && !_f.done && (_b = _e.return)) { _b.call(_e); }
} }
finally { if (e_6) { throw e_6.error; } } finally { if (e_3) { throw e_3.error; } }
} }
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) { _a.call(_c); }
}
finally { if (e_2) { throw e_2.error; } }
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(function (_) {
});
}
else {
this.__rendering__ = true;
Promise.all(promises).then(function (_) {
_this.__rendering__ = false; _this.__rendering__ = false;
Promise.all(promises).then(function (_) { _this.onRenderFinished();
_this.onRenderFinished(); });
});
}, 0);
} }
}; };
Panel.prototype.onRenderFinished = function () { Panel.prototype.onRenderFinished = function () {

View File

@ -980,74 +980,37 @@ class Panel {
return this.context.callNative("shader", "render", model); return this.context.callNative("shader", "render", model);
} }
hookBeforeNativeCall() { hookBeforeNativeCall() {
if (Environment.platform !== 'web') {
this.__root__.clean();
for (let map of this.headviews.values()) {
for (let v of map.values()) {
v.clean();
}
}
}
} }
hookAfterNativeCall() { hookAfterNativeCall() {
if (this.destroyed) { if (this.destroyed) {
return; return;
} }
const promises = []; const promises = [];
if (Environment.platform !== 'web') { if (this.__root__.isDirty()) {
//Here insert a native call to ensure the promise is resolved done. const model = this.__root__.toModel();
//nativeEmpty() promises.push(this.nativeRender(model));
if (this.__root__.isDirty()) { this.__root__.clean();
const model = this.__root__.toModel(); }
promises.push(this.nativeRender(model)); for (let map of this.headviews.values()) {
} for (let v of map.values()) {
for (let map of this.headviews.values()) { if (v.isDirty()) {
for (let v of map.values()) { const model = v.toModel();
if (v.isDirty()) { promises.push(this.nativeRender(model));
const model = v.toModel(); v.clean();
promises.push(this.nativeRender(model));
}
} }
} }
if (this.__rendering__) { }
//skip if (this.__rendering__) {
Promise.all(promises).then(_ => { //skip
}); Promise.all(promises).then(_ => {
} });
else {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
this.onRenderFinished();
});
}
} }
else { else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true; this.__rendering__ = true;
Function("return this")().setTimeout(() => { Promise.all(promises).then(_ => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
promises.push(this.nativeRender(model));
this.__root__.clean();
}
for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model = v.toModel();
promises.push(this.nativeRender(model));
v.clean();
}
}
}
this.__rendering__ = false; this.__rendering__ = false;
Promise.all(promises).then(_ => { this.onRenderFinished();
this.onRenderFinished(); });
});
}, 0);
} }
} }
onRenderFinished() { onRenderFinished() {

View File

@ -1222,7 +1222,7 @@ var doric = (function (exports) {
*/ */
function hookBeforeNativeCall(context) { function hookBeforeNativeCall(context) {
if (context) { if (context) {
Reflect.defineMetadata('__doric_context__', context, global$2); setContext(context);
context.hookBeforeNativeCall(); context.hookBeforeNativeCall();
} }
} }

View File

@ -1200,7 +1200,7 @@ var doric = (function (exports) {
*/ */
function hookBeforeNativeCall(context) { function hookBeforeNativeCall(context) {
if (context) { if (context) {
Reflect.defineMetadata('__doric_context__', context, global$1); setContext(context);
context.hookBeforeNativeCall(); context.hookBeforeNativeCall();
} }
} }

View File

@ -1229,7 +1229,7 @@ var Reflect$1;
*/ */
function hookBeforeNativeCall(context) { function hookBeforeNativeCall(context) {
if (context) { if (context) {
Reflect.defineMetadata('__doric_context__', context, global$2); setContext(context);
context.hookBeforeNativeCall(); context.hookBeforeNativeCall();
} }
} }
@ -2501,74 +2501,37 @@ class Panel {
return this.context.callNative("shader", "render", model); return this.context.callNative("shader", "render", model);
} }
hookBeforeNativeCall() { hookBeforeNativeCall() {
if (Environment.platform !== 'web') {
this.__root__.clean();
for (let map of this.headviews.values()) {
for (let v of map.values()) {
v.clean();
}
}
}
} }
hookAfterNativeCall() { hookAfterNativeCall() {
if (this.destroyed) { if (this.destroyed) {
return; return;
} }
const promises = []; const promises = [];
if (Environment.platform !== 'web') { if (this.__root__.isDirty()) {
//Here insert a native call to ensure the promise is resolved done. const model = this.__root__.toModel();
//nativeEmpty() promises.push(this.nativeRender(model));
if (this.__root__.isDirty()) { this.__root__.clean();
const model = this.__root__.toModel(); }
promises.push(this.nativeRender(model)); for (let map of this.headviews.values()) {
} for (let v of map.values()) {
for (let map of this.headviews.values()) { if (v.isDirty()) {
for (let v of map.values()) { const model = v.toModel();
if (v.isDirty()) { promises.push(this.nativeRender(model));
const model = v.toModel(); v.clean();
promises.push(this.nativeRender(model));
}
} }
} }
if (this.__rendering__) { }
//skip if (this.__rendering__) {
Promise.all(promises).then(_ => { //skip
}); Promise.all(promises).then(_ => {
} });
else {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
this.onRenderFinished();
});
}
} }
else { else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true; this.__rendering__ = true;
Function("return this")().setTimeout(() => { Promise.all(promises).then(_ => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
promises.push(this.nativeRender(model));
this.__root__.clean();
}
for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model = v.toModel();
promises.push(this.nativeRender(model));
v.clean();
}
}
}
this.__rendering__ = false; this.__rendering__ = false;
Promise.all(promises).then(_ => { this.onRenderFinished();
this.onRenderFinished(); });
});
}, 0);
} }
} }
onRenderFinished() { onRenderFinished() {

View File

@ -18,7 +18,7 @@ import { loge } from "../util/log";
import "reflect-metadata"; import "reflect-metadata";
function hookBeforeNativeCall(context) { function hookBeforeNativeCall(context) {
if (context) { if (context) {
Reflect.defineMetadata('__doric_context__', context, global); setContext(context);
context.hookBeforeNativeCall(); context.hookBeforeNativeCall();
} }
} }

View File

@ -166,74 +166,37 @@ export class Panel {
return this.context.callNative("shader", "render", model); return this.context.callNative("shader", "render", model);
} }
hookBeforeNativeCall() { hookBeforeNativeCall() {
if (Environment.platform !== 'web') {
this.__root__.clean();
for (let map of this.headviews.values()) {
for (let v of map.values()) {
v.clean();
}
}
}
} }
hookAfterNativeCall() { hookAfterNativeCall() {
if (this.destroyed) { if (this.destroyed) {
return; return;
} }
const promises = []; const promises = [];
if (Environment.platform !== 'web') { if (this.__root__.isDirty()) {
//Here insert a native call to ensure the promise is resolved done. const model = this.__root__.toModel();
//nativeEmpty() promises.push(this.nativeRender(model));
if (this.__root__.isDirty()) { this.__root__.clean();
const model = this.__root__.toModel(); }
promises.push(this.nativeRender(model)); for (let map of this.headviews.values()) {
} for (let v of map.values()) {
for (let map of this.headviews.values()) { if (v.isDirty()) {
for (let v of map.values()) { const model = v.toModel();
if (v.isDirty()) { promises.push(this.nativeRender(model));
const model = v.toModel(); v.clean();
promises.push(this.nativeRender(model));
}
} }
} }
if (this.__rendering__) { }
//skip if (this.__rendering__) {
Promise.all(promises).then(_ => { //skip
}); Promise.all(promises).then(_ => {
} });
else {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
this.onRenderFinished();
});
}
} }
else { else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true; this.__rendering__ = true;
Function("return this")().setTimeout(() => { Promise.all(promises).then(_ => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
promises.push(this.nativeRender(model));
this.__root__.clean();
}
for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model = v.toModel();
promises.push(this.nativeRender(model));
v.clean();
}
}
}
this.__rendering__ = false; this.__rendering__ = false;
Promise.all(promises).then(_ => { this.onRenderFinished();
this.onRenderFinished(); });
});
}, 0);
} }
} }
onRenderFinished() { onRenderFinished() {

View File

@ -54,7 +54,7 @@ declare function nativeClearTimer(timerId: number): void
function hookBeforeNativeCall(context?: Context) { function hookBeforeNativeCall(context?: Context) {
if (context) { if (context) {
Reflect.defineMetadata('__doric_context__', context, global) setContext(context)
context.hookBeforeNativeCall() context.hookBeforeNativeCall()
} }
} }

View File

@ -65,7 +65,7 @@ declare function nativeClearTimer(timerId: number): void
function hookBeforeNativeCall(context?: Context) { function hookBeforeNativeCall(context?: Context) {
if (context) { if (context) {
Reflect.defineMetadata('__doric_context__', context, global) setContext(context)
context.hookBeforeNativeCall() context.hookBeforeNativeCall()
} }
} }

View File

@ -195,14 +195,6 @@ export abstract class Panel {
} }
private hookBeforeNativeCall() { private hookBeforeNativeCall() {
if (Environment.platform !== 'web') {
this.__root__.clean()
for (let map of this.headviews.values()) {
for (let v of map.values()) {
v.clean()
}
}
}
} }
private hookAfterNativeCall() { private hookAfterNativeCall() {
@ -210,58 +202,30 @@ export abstract class Panel {
return return
} }
const promises: Promise<any>[] = [] const promises: Promise<any>[] = []
if (Environment.platform !== 'web') { if (this.__root__.isDirty()) {
//Here insert a native call to ensure the promise is resolved done. const model = this.__root__.toModel()
//nativeEmpty() promises.push(this.nativeRender(model))
if (this.__root__.isDirty()) { this.__root__.clean()
const model = this.__root__.toModel() }
promises.push(this.nativeRender(model)) for (let map of this.headviews.values()) {
} for (let v of map.values()) {
for (let map of this.headviews.values()) { if (v.isDirty()) {
for (let v of map.values()) { const model = v.toModel()
if (v.isDirty()) {
const model = v.toModel()
promises.push(this.nativeRender(model))
}
}
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
})
} else {
this.__rendering__ = true
Promise.all(promises).then(_ => {
this.__rendering__ = false
this.onRenderFinished()
})
}
} else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true
Function("return this")().setTimeout(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel()
promises.push(this.nativeRender(model)) promises.push(this.nativeRender(model))
this.__root__.clean() v.clean()
}
for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model = v.toModel()
promises.push(this.nativeRender(model))
v.clean()
}
}
} }
}
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
})
} else {
this.__rendering__ = true
Promise.all(promises).then(_ => {
this.__rendering__ = false this.__rendering__ = false
Promise.all(promises).then(_ => { this.onRenderFinished()
this.onRenderFinished() })
})
}, 0)
} }
} }

View File

@ -1202,7 +1202,7 @@ var doric = (function (exports) {
*/ */
function hookBeforeNativeCall(context) { function hookBeforeNativeCall(context) {
if (context) { if (context) {
Reflect.defineMetadata('__doric_context__', context, global$1); setContext(context);
context.hookBeforeNativeCall(); context.hookBeforeNativeCall();
} }
} }
@ -2555,74 +2555,37 @@ class Panel {
return this.context.callNative("shader", "render", model); return this.context.callNative("shader", "render", model);
} }
hookBeforeNativeCall() { hookBeforeNativeCall() {
if (Environment.platform !== 'web') {
this.__root__.clean();
for (let map of this.headviews.values()) {
for (let v of map.values()) {
v.clean();
}
}
}
} }
hookAfterNativeCall() { hookAfterNativeCall() {
if (this.destroyed) { if (this.destroyed) {
return; return;
} }
const promises = []; const promises = [];
if (Environment.platform !== 'web') { if (this.__root__.isDirty()) {
//Here insert a native call to ensure the promise is resolved done. const model = this.__root__.toModel();
//nativeEmpty() promises.push(this.nativeRender(model));
if (this.__root__.isDirty()) { this.__root__.clean();
const model = this.__root__.toModel(); }
promises.push(this.nativeRender(model)); for (let map of this.headviews.values()) {
} for (let v of map.values()) {
for (let map of this.headviews.values()) { if (v.isDirty()) {
for (let v of map.values()) { const model = v.toModel();
if (v.isDirty()) { promises.push(this.nativeRender(model));
const model = v.toModel(); v.clean();
promises.push(this.nativeRender(model));
}
} }
} }
if (this.__rendering__) { }
//skip if (this.__rendering__) {
Promise.all(promises).then(_ => { //skip
}); Promise.all(promises).then(_ => {
} });
else {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
this.onRenderFinished();
});
}
} }
else { else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true; this.__rendering__ = true;
Function("return this")().setTimeout(() => { Promise.all(promises).then(_ => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
promises.push(this.nativeRender(model));
this.__root__.clean();
}
for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model = v.toModel();
promises.push(this.nativeRender(model));
v.clean();
}
}
}
this.__rendering__ = false; this.__rendering__ = false;
Promise.all(promises).then(_ => { this.onRenderFinished();
this.onRenderFinished(); });
});
}, 0);
} }
} }
onRenderFinished() { onRenderFinished() {
@ -7525,7 +7488,6 @@ ${content}
injectGlobalObject("Environment", { injectGlobalObject("Environment", {
platform: "web" platform: "web"
}); });
injectGlobalObject("nativeEmpty", () => undefined);
injectGlobalObject('nativeLog', (type, message) => { injectGlobalObject('nativeLog', (type, message) => {
switch (type) { switch (type) {
case 'd': case 'd':
@ -7578,13 +7540,16 @@ ${content}
if (ret instanceof Promise) { if (ret instanceof Promise) {
ret.then(e => { ret.then(e => {
sandbox.jsCallResolve(contextId, callbackId, e); sandbox.jsCallResolve(contextId, callbackId, e);
markNeedHook();
}, e => { }, e => {
sandbox.jsCallReject(contextId, callbackId, e); sandbox.jsCallReject(contextId, callbackId, e);
markNeedHook();
}); });
} }
else if (ret !== undefined) { else if (ret !== undefined) {
Promise.resolve(ret).then((ret) => { Promise.resolve(ret).then((ret) => {
sandbox.jsCallResolve(contextId, callbackId, ret); sandbox.jsCallResolve(contextId, callbackId, ret);
markNeedHook();
}); });
} }
return true; return true;
@ -7593,12 +7558,14 @@ ${content}
if (repeat) { if (repeat) {
const handleId = originSetInterval(() => { const handleId = originSetInterval(() => {
sandbox.jsCallbackTimer(timerId); sandbox.jsCallbackTimer(timerId);
markNeedHook();
}, time); }, time);
timers.set(timerId, { handleId, repeat }); timers.set(timerId, { handleId, repeat });
} }
else { else {
const handleId = originSetTimeout(() => { const handleId = originSetTimeout(() => {
sandbox.jsCallbackTimer(timerId); sandbox.jsCallbackTimer(timerId);
markNeedHook();
}, time); }, time);
timers.set(timerId, { handleId, repeat }); timers.set(timerId, { handleId, repeat });
} }
@ -7625,6 +7592,17 @@ ${content}
document.body.removeChild(scriptElement); document.body.removeChild(scriptElement);
} }
} }
let requesting = false;
function markNeedHook() {
if (requesting) {
return;
}
requesting = true;
requestAnimationFrame(() => {
sandbox.jsHookAfterNativeCall();
requesting = false;
});
}
initDoric(); initDoric();
const doricContexts = new Map; const doricContexts = new Map;
@ -7663,7 +7641,9 @@ ${content}
for (let i = 0; i < arguments.length; i++) { for (let i = 0; i < arguments.length; i++) {
argumentsList.push(arguments[i]); argumentsList.push(arguments[i]);
} }
return Reflect.apply(sandbox.jsCallEntityMethod, this.panel, argumentsList); const ret = Reflect.apply(sandbox.jsCallEntityMethod, this.panel, argumentsList);
markNeedHook();
return ret;
} }
pureInvokeEntityMethod(method, ...otherArgs) { pureInvokeEntityMethod(method, ...otherArgs) {
const argumentsList = [this.contextId]; const argumentsList = [this.contextId];
@ -7841,6 +7821,7 @@ ${content}
exports.destroyContext = destroyContext; exports.destroyContext = destroyContext;
exports.injectGlobalObject = injectGlobalObject; exports.injectGlobalObject = injectGlobalObject;
exports.loadJS = loadJS; exports.loadJS = loadJS;
exports.markNeedHook = markNeedHook;
exports.pixelString2Number = pixelString2Number; exports.pixelString2Number = pixelString2Number;
exports.registerJSBundle = registerJSBundle; exports.registerJSBundle = registerJSBundle;
exports.registerPlugin = registerPlugin; exports.registerPlugin = registerPlugin;

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
import { jsObtainContext, jsCallEntityMethod, pureCallEntityMethod } from 'doric/src/runtime/sandbox' import { jsObtainContext, jsCallEntityMethod, pureCallEntityMethod } from 'doric/src/runtime/sandbox'
import { Panel } from 'doric' import { Panel } from 'doric'
import { DoricPlugin } from "./DoricPlugin" import { DoricPlugin } from "./DoricPlugin"
import { createContext, destroyContext } from "./DoricDriver" import { createContext, destroyContext, markNeedHook } from "./DoricDriver"
import { DoricStackNode } from './shader/DoricStackNode' import { DoricStackNode } from './shader/DoricStackNode'
import { DoricViewNode } from './shader/DoricViewNode' import { DoricViewNode } from './shader/DoricViewNode'
const doricContexts: Map<string, DoricContext> = new Map const doricContexts: Map<string, DoricContext> = new Map
@ -51,7 +51,9 @@ export class DoricContext {
for (let i = 0; i < arguments.length; i++) { for (let i = 0; i < arguments.length; i++) {
argumentsList.push(arguments[i]) argumentsList.push(arguments[i])
} }
return Reflect.apply(jsCallEntityMethod, this.panel, argumentsList) const ret = Reflect.apply(jsCallEntityMethod, this.panel, argumentsList)
markNeedHook()
return ret
} }
pureInvokeEntityMethod(method: string, ...otherArgs: any) { pureInvokeEntityMethod(method: string, ...otherArgs: any) {

View File

@ -1,4 +1,4 @@
import { jsCallResolve, jsCallReject, jsCallbackTimer, jsReleaseContext } from 'doric/src/runtime/sandbox' import { jsCallResolve, jsCallReject, jsCallbackTimer, jsReleaseContext, jsHookAfterNativeCall } 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'
@ -44,8 +44,6 @@ function initDoric() {
platform: "web" platform: "web"
}) })
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':
@ -99,13 +97,16 @@ function initDoric() {
ret.then( ret.then(
e => { e => {
jsCallResolve(contextId, callbackId, e) jsCallResolve(contextId, callbackId, e)
markNeedHook()
}, },
e => { e => {
jsCallReject(contextId, callbackId, e) jsCallReject(contextId, callbackId, e)
markNeedHook()
}) })
} else if (ret !== undefined) { } else if (ret !== undefined) {
Promise.resolve(ret).then((ret) => { Promise.resolve(ret).then((ret) => {
jsCallResolve(contextId, callbackId, ret) jsCallResolve(contextId, callbackId, ret)
markNeedHook()
}) })
} }
return true return true
@ -115,11 +116,13 @@ function initDoric() {
if (repeat) { if (repeat) {
const handleId = originSetInterval(() => { const handleId = originSetInterval(() => {
jsCallbackTimer(timerId) jsCallbackTimer(timerId)
markNeedHook()
}, time) }, time)
timers.set(timerId, { handleId, repeat }) timers.set(timerId, { handleId, repeat })
} else { } else {
const handleId = originSetTimeout(() => { const handleId = originSetTimeout(() => {
jsCallbackTimer(timerId) jsCallbackTimer(timerId)
markNeedHook()
}, time) }, time)
timers.set(timerId, { handleId, repeat }) timers.set(timerId, { handleId, repeat })
} }
@ -146,4 +149,17 @@ export function destroyContext(contextId: string) {
document.body.removeChild(scriptElement) document.body.removeChild(scriptElement)
} }
} }
let requesting = false
export function markNeedHook() {
if (requesting) {
return
}
requesting = true
requestAnimationFrame(() => {
jsHookAfterNativeCall()
requesting = false
})
}
initDoric() initDoric()