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); this.context.shader.render(model);
} }
hookBeforeNativeCall() { hookBeforeNativeCall() {
this.__root__.clean();
for (let v of this.headviews.values()) {
v.clean();
}
} }
hookAfterNativeCall() { hookAfterNativeCall() {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.
if (Environment.platform === 'h5') { Promise.resolve().then(() => {
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();
if (this.__root__.isDirty()) { if (this.__root__.isDirty()) {
const model = this.__root__.toModel(); const model = this.__root__.toModel();
this.nativeRender(model); this.nativeRender(model);
this.__root__.clean();
} }
for (let v of this.headviews.values()) { for (let v of this.headviews.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); this.nativeRender(model);
v.clean();
} }
} }
} });
} }
} }
__decorate$2([ __decorate$2([

View File

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

View File

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