feat:refact View Dirty Props,prepare to use in ListView

This commit is contained in:
pengfei.zhou
2019-11-12 17:59:38 +08:00
parent dab3c00b4c
commit eea7eb5d27
4 changed files with 30 additions and 4 deletions

View File

@@ -44,6 +44,10 @@ export class List extends Superview {
return this.cachedViews.get(id)
}
allSubviews() {
return this.cachedViews.values()
}
@Property
itemCount = 0

View File

@@ -99,8 +99,8 @@ export abstract class Panel {
private retrospectView(ids: string[]): View {
return ids.reduce((acc: View, cur) => {
if (Reflect.has(acc, "subViewById")) {
return Reflect.apply(Reflect.get(acc, "subViewById"), acc, [cur])
if (Reflect.has(acc, "subviewById")) {
return Reflect.apply(Reflect.get(acc, "subviewById"), acc, [cur])
}
return acc
}, this.__root__)

View File

@@ -254,6 +254,20 @@ export abstract class View implements Modeling, IView {
export abstract class Superview extends View {
abstract subviewById(id: string): View | undefined
abstract allSubviews(): Iterable<View>
isDirty() {
if (super.isDirty()) {
return true
} else {
for (const v of this.allSubviews()) {
if (v.isDirty()) {
return true
}
}
}
return false
}
}
export abstract class Group extends Superview {
@@ -276,6 +290,10 @@ export abstract class Group extends Superview {
return undefined
}
allSubviews() {
return this.children
}
addChild(view: View) {
this.children.push(view)
}