optimize js code

This commit is contained in:
pengfei.zhou
2021-08-31 12:49:47 +08:00
committed by osborn
parent 612e5a4a07
commit 1b10106eb3
31 changed files with 109 additions and 271 deletions

View File

@@ -354,6 +354,10 @@ export abstract class View implements Modeling {
@Property
flexConfig?: FlexConfig
set props(props: Partial<this>) {
this.apply(props)
}
doAnimation(context: BridgeContext, animation: IAnimation) {
return this.nativeChannel(context, "doAnimation")(animation.toModel()).then((args) => {
for (let key in args) {

View File

@@ -33,9 +33,7 @@ export function draggable(views: View | View[], config?: Partial<Draggable>) {
})
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
}
return ret
}

View File

@@ -121,9 +121,7 @@ export function flowItem(item: View | View[], config?: Partial<FlowLayoutItem>)
})
}
if (config) {
for (let key in config) {
Reflect.set(it, key, Reflect.get(config, key, config), it)
}
it.apply(config)
}
})
}

View File

@@ -112,8 +112,6 @@ export class Image extends View {
export function image(config: Partial<Image>) {
const ret = new Image
ret.layoutConfig = layoutConfig().fit()
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
return ret
}

View File

@@ -147,8 +147,6 @@ export enum InputType {
export function input(config: Partial<Input>) {
const ret = new Input
ret.layoutConfig = layoutConfig().just()
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
return ret
}

View File

@@ -44,9 +44,7 @@ export function stack(views: View[], config?: Partial<Stack>) {
ret.addChild(v)
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
}
return ret
}
@@ -58,9 +56,7 @@ export function hlayout(views: View[], config?: Partial<HLayout>) {
ret.addChild(v)
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
}
return ret
}
@@ -72,9 +68,7 @@ export function vlayout(views: View[], config?: Partial<VLayout>) {
ret.addChild(v)
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
}
return ret
}
@@ -91,9 +85,7 @@ export function flexlayout(views: View[], config?: Partial<FlexLayout>) {
ret.addChild(v)
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
}
return ret
}

View File

@@ -114,9 +114,7 @@ export class List extends Superview {
export function list(config: Partial<List>) {
const ret = new List
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
return ret
}
@@ -131,9 +129,7 @@ export function listItem(item: View | View[], config?: Partial<ListItem>) {
})
}
if (config) {
for (let key in config) {
Reflect.set(it, key, Reflect.get(config, key, config), it)
}
it.apply(config)
}
})
}

View File

@@ -47,9 +47,7 @@ export class Refreshable extends Superview {
export function refreshable(config: Partial<Refreshable>) {
const ret = new Refreshable
ret.layoutConfig = layoutConfig().fit()
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
return ret
}

View File

@@ -21,9 +21,7 @@ export function scroller(content: View, config?: Partial<Scroller>) {
return (new Scroller).also(v => {
v.layoutConfig = layoutConfig().fit()
if (config) {
for (let key in config) {
Reflect.set(v, key, Reflect.get(config, key, config), v)
}
v.apply(config)
}
v.content = content
})

View File

@@ -83,9 +83,7 @@ export class Slider extends Superview {
export function slider(config: Partial<Slider>) {
const ret = new Slider
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
return ret
}

View File

@@ -44,8 +44,6 @@ export function switchView(config: Partial<Switch>) {
ret.layoutConfig = layoutConfig().just()
ret.width = 50
ret.height = 30
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
return ret
}

View File

@@ -72,8 +72,6 @@ export class Text extends View {
export function text(config: Partial<Text>) {
const ret = new Text
ret.layoutConfig = layoutConfig().fit()
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
ret.apply(config)
return ret
}