auto modeling
This commit is contained in:
parent
b76851e044
commit
d255c05aef
@ -1,6 +1,10 @@
|
||||
import { Text } from "./view/view";
|
||||
import { Color } from "./util/color";
|
||||
|
||||
const v = new Text
|
||||
v.width = 1
|
||||
console.log('start:')
|
||||
v.height
|
||||
v.width = 20
|
||||
v.height = 30
|
||||
v.left = 5
|
||||
v.top = 5
|
||||
v.bgColor = Color.parse('#00ff00')
|
||||
console.log(v.toModel())
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { Modeling } from "./types";
|
||||
|
||||
/**
|
||||
* Store color as format AARRGGBB or RRGGBB
|
||||
*/
|
||||
export class Color {
|
||||
export class Color implements Modeling {
|
||||
|
||||
static TRANSPARENT = new Color(0)
|
||||
_value: number = 0
|
||||
|
||||
@ -32,7 +35,8 @@ export class Color {
|
||||
return color
|
||||
}
|
||||
}
|
||||
toNumber() {
|
||||
|
||||
toModel() {
|
||||
return this._value
|
||||
}
|
||||
}
|
||||
|
@ -18,3 +18,9 @@ export function Property(target: IWatcher, propKey: string) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export interface Modeling {
|
||||
toModel(): Model
|
||||
}
|
||||
|
||||
export type Model = string | number | boolean | Modeling | { [index: string]: Model | undefined }
|
@ -1,9 +1,8 @@
|
||||
import { Color, GradientColor } from "../util/color"
|
||||
import { Property, IWatcher } from "../util/types";
|
||||
import { Property, IWatcher, Modeling, Model } from "../util/types";
|
||||
|
||||
|
||||
export abstract class View implements IWatcher {
|
||||
|
||||
export abstract class View implements IWatcher, Modeling {
|
||||
@Property
|
||||
width: number = 0
|
||||
|
||||
@ -63,8 +62,23 @@ export abstract class View implements IWatcher {
|
||||
}
|
||||
/** Anchor end*/
|
||||
|
||||
onPropertyChanged(propKey: string, oldV: any, newV: any): void {
|
||||
console.log(`onPropertyChanged:${propKey},old value is ${oldV},new value is ${newV}`)
|
||||
__dirty_props__?: { [index: string]: Model | undefined }
|
||||
|
||||
onPropertyChanged(propKey: string, oldV: Model, newV: Model): void {
|
||||
//console.log(`onPropertyChanged:${propKey},old value is ${oldV},new value is ${newV}`)
|
||||
if (this.__dirty_props__ === undefined) {
|
||||
this.__dirty_props__ = {}
|
||||
}
|
||||
if (newV instanceof Object
|
||||
&& Reflect.has(newV, 'toModel')
|
||||
&& Reflect.get(newV, 'toModel') instanceof Function) {
|
||||
newV = Reflect.apply(Reflect.get(newV, 'toModel'), newV, [])
|
||||
}
|
||||
this.__dirty_props__[propKey] = newV
|
||||
}
|
||||
|
||||
toModel() {
|
||||
return this.__dirty_props__ || {}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user