add view idenitify
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { Page } from '../ui/page'
|
||||
import { Panel } from '../ui/panel'
|
||||
import { View } from '../ui/view'
|
||||
|
||||
export interface Driver {
|
||||
/**
|
||||
* Create and destory page
|
||||
*/
|
||||
createPage(): Page
|
||||
destoryPage(): Page
|
||||
createPage(): Panel
|
||||
destoryPage(): Panel
|
||||
|
||||
/**
|
||||
* Page lifecycle
|
||||
@@ -20,4 +20,9 @@ export interface Driver {
|
||||
* Page render
|
||||
*/
|
||||
dispatchBuild(): View
|
||||
}
|
||||
|
||||
export interface Responser {
|
||||
constructor(): void
|
||||
respond(action: string, extra: any): void
|
||||
}
|
@@ -10,11 +10,11 @@ export function Registor<T extends { new(...args: any[]): {} }>(constructor: T)
|
||||
}
|
||||
|
||||
|
||||
export abstract class Page {
|
||||
onCreate(): void { }
|
||||
onDestory(): void { }
|
||||
onShow(): void { }
|
||||
onHidden(): void { }
|
||||
export abstract class Panel {
|
||||
onCreate() { }
|
||||
onDestory() { }
|
||||
onShow() { }
|
||||
onHidden() { }
|
||||
|
||||
abstract build(): View
|
||||
|
||||
@@ -22,15 +22,16 @@ export abstract class Page {
|
||||
/**
|
||||
* Native Call
|
||||
*/
|
||||
private __onCreate__(): void {
|
||||
private __onCreate__() {
|
||||
Reflect.defineMetadata(Symbol.for("context"), context, Reflect.getPrototypeOf(context))
|
||||
this.onCreate()
|
||||
}
|
||||
|
||||
private __onDestory__(): void {
|
||||
private __onDestory__() {
|
||||
this.onDestory()
|
||||
}
|
||||
|
||||
private __onShow__(): void {
|
||||
private __onShow__() {
|
||||
this.onShow()
|
||||
}
|
||||
|
||||
@@ -41,4 +42,8 @@ export abstract class Page {
|
||||
private __build__(): View {
|
||||
return this.build()
|
||||
}
|
||||
|
||||
private __responed__(viewId: string, action: string, args: any) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
import { Color, GradientColor } from "../util/color"
|
||||
import { Modeling, Model } from "../util/types";
|
||||
import "reflect-metadata"
|
||||
import { uniqueId } from "../util/uniqueId";
|
||||
|
||||
export function Property(target: Object, propKey: string) {
|
||||
Reflect.defineMetadata(propKey, true, target)
|
||||
@@ -33,6 +34,13 @@ export abstract class View implements Modeling {
|
||||
|
||||
@Property
|
||||
alpha?: number
|
||||
|
||||
@Property
|
||||
hidden?: boolean
|
||||
|
||||
@Property
|
||||
viewId = uniqueId('ViewId')
|
||||
|
||||
constructor() {
|
||||
return new Proxy(this, {
|
||||
get: (target, p) => {
|
||||
@@ -92,7 +100,11 @@ export abstract class View implements Modeling {
|
||||
}
|
||||
|
||||
toModel() {
|
||||
return this.__dirty_props__ || {}
|
||||
return {
|
||||
id: this.viewId,
|
||||
type: this.constructor.name,
|
||||
props: this.__dirty_props__,
|
||||
}
|
||||
}
|
||||
|
||||
@Property
|
||||
|
Reference in New Issue
Block a user