Group and view

This commit is contained in:
pengfei.zhou
2019-07-20 18:37:50 +08:00
parent e35ab68014
commit e85b60d05c
4 changed files with 112 additions and 12 deletions

View File

@@ -1,5 +1,18 @@
export interface Modeling {
toModel(): Model
}
export function obj2Model(obj: Model): Model {
if (obj instanceof Array) {
return obj.map(e => obj2Model(e)) as Model
} else if (obj instanceof Object
&& Reflect.has(obj, 'toModel')
&& Reflect.get(obj, 'toModel') instanceof Function) {
obj = Reflect.apply(Reflect.get(obj, 'toModel'), obj, [])
return obj
} else {
return obj
}
}
export type Model = string | number | boolean | Modeling | { [index: string]: Model | undefined }
type _M = string | number | boolean | Modeling | { [index: string]: Model | undefined }
export type Model = _M | Array<_M>