feat:Check dirty use Promise to scheme it to micro queue

This commit is contained in:
pengfei.zhou 2019-12-25 15:13:36 +08:00 committed by osborn
parent 4b1fcc439d
commit 665d11f8be
3 changed files with 12 additions and 65 deletions

View File

@ -736,40 +736,23 @@ class Panel {
this.context.shader.render(model);
}
hookBeforeNativeCall() {
this.__root__.clean();
for (let v of this.headviews.values()) {
v.clean();
}
}
hookAfterNativeCall() {
//Here insert a native call to ensure the promise is resolved done.
if (Environment.platform === 'h5') {
setTimeout(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
this.nativeRender(model);
}
for (let v of this.headviews.values()) {
if (v.isDirty()) {
const model = v.toModel();
this.nativeRender(model);
}
}
}, 0);
}
else {
nativeEmpty();
Promise.resolve().then(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
this.nativeRender(model);
this.__root__.clean();
}
for (let v of this.headviews.values()) {
if (v.isDirty()) {
const model = v.toModel();
this.nativeRender(model);
v.clean();
}
}
}
});
}
}
__decorate$2([

View File

@ -2184,40 +2184,23 @@ class Panel {
this.context.shader.render(model);
}
hookBeforeNativeCall() {
this.__root__.clean();
for (let v of this.headviews.values()) {
v.clean();
}
}
hookAfterNativeCall() {
//Here insert a native call to ensure the promise is resolved done.
if (Environment.platform === 'h5') {
setTimeout(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
this.nativeRender(model);
}
for (let v of this.headviews.values()) {
if (v.isDirty()) {
const model = v.toModel();
this.nativeRender(model);
}
}
}, 0);
}
else {
nativeEmpty();
Promise.resolve().then(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
this.nativeRender(model);
this.__root__.clean();
}
for (let v of this.headviews.values()) {
if (v.isDirty()) {
const model = v.toModel();
this.nativeRender(model);
v.clean();
}
}
}
});
}
}
__decorate$2([

View File

@ -20,7 +20,6 @@ import { Model } from '../util/types'
import { Root } from '../widget/layouts'
import { BridgeContext } from '../runtime/global'
export function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor) {
const originVal = descriptor.value
descriptor.value = function () {
@ -32,8 +31,6 @@ export function NativeCall(target: Panel, propertyKey: string, descriptor: Prope
type Frame = { width: number, height: number }
declare function nativeEmpty(): void
export abstract class Panel {
context!: BridgeContext
onCreate() { }
@ -144,40 +141,24 @@ export abstract class Panel {
}
private hookBeforeNativeCall() {
this.__root__.clean()
for (let v of this.headviews.values()) {
v.clean()
}
}
private hookAfterNativeCall() {
//Here insert a native call to ensure the promise is resolved done.
if (Environment.platform === 'h5') {
setTimeout(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel()
this.nativeRender(model)
}
for (let v of this.headviews.values()) {
if (v.isDirty()) {
const model = v.toModel()
this.nativeRender(model)
}
}
}, 0)
} else {
nativeEmpty()
Promise.resolve().then(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel()
this.nativeRender(model)
this.__root__.clean()
}
for (let v of this.headviews.values()) {
if (v.isDirty()) {
const model = v.toModel()
this.nativeRender(model)
v.clean()
}
}
}
})
}
}