Optimize unify panel hook after code
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { jsObtainContext, jsCallEntityMethod, pureCallEntityMethod } from 'doric/src/runtime/sandbox'
|
||||
import { Panel } from 'doric'
|
||||
import { DoricPlugin } from "./DoricPlugin"
|
||||
import { createContext, destroyContext } from "./DoricDriver"
|
||||
import { createContext, destroyContext, markNeedHook } from "./DoricDriver"
|
||||
import { DoricStackNode } from './shader/DoricStackNode'
|
||||
import { DoricViewNode } from './shader/DoricViewNode'
|
||||
const doricContexts: Map<string, DoricContext> = new Map
|
||||
@@ -51,7 +51,9 @@ export class DoricContext {
|
||||
for (let i = 0; i < arguments.length; 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) {
|
||||
|
@@ -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 { getDoricContext } from './DoricContext'
|
||||
import { DoricPlugin } from './DoricPlugin'
|
||||
@@ -44,8 +44,6 @@ function initDoric() {
|
||||
platform: "web"
|
||||
})
|
||||
|
||||
injectGlobalObject("nativeEmpty", () => undefined)
|
||||
|
||||
injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => {
|
||||
switch (type) {
|
||||
case 'd':
|
||||
@@ -99,13 +97,16 @@ function initDoric() {
|
||||
ret.then(
|
||||
e => {
|
||||
jsCallResolve(contextId, callbackId, e)
|
||||
markNeedHook()
|
||||
},
|
||||
e => {
|
||||
jsCallReject(contextId, callbackId, e)
|
||||
markNeedHook()
|
||||
})
|
||||
} else if (ret !== undefined) {
|
||||
Promise.resolve(ret).then((ret) => {
|
||||
jsCallResolve(contextId, callbackId, ret)
|
||||
markNeedHook()
|
||||
})
|
||||
}
|
||||
return true
|
||||
@@ -115,11 +116,13 @@ function initDoric() {
|
||||
if (repeat) {
|
||||
const handleId = originSetInterval(() => {
|
||||
jsCallbackTimer(timerId)
|
||||
markNeedHook()
|
||||
}, time)
|
||||
timers.set(timerId, { handleId, repeat })
|
||||
} else {
|
||||
const handleId = originSetTimeout(() => {
|
||||
jsCallbackTimer(timerId)
|
||||
markNeedHook()
|
||||
}, time)
|
||||
timers.set(timerId, { handleId, repeat })
|
||||
}
|
||||
@@ -146,4 +149,17 @@ export function destroyContext(contextId: string) {
|
||||
document.body.removeChild(scriptElement)
|
||||
}
|
||||
}
|
||||
|
||||
let requesting = false
|
||||
|
||||
export function markNeedHook() {
|
||||
if (requesting) {
|
||||
return
|
||||
}
|
||||
requesting = true
|
||||
requestAnimationFrame(() => {
|
||||
jsHookAfterNativeCall()
|
||||
requesting = false
|
||||
})
|
||||
}
|
||||
initDoric()
|
Reference in New Issue
Block a user