add view idenitify

This commit is contained in:
pengfei.zhou 2019-07-18 11:34:43 +08:00
parent 44ad1a58c7
commit e6bc920ab7
6 changed files with 42 additions and 20 deletions

View File

@ -1,12 +1,11 @@
import { Text, Alignment, VLayout, Gravity } from "./src/ui/view"; import { Text, Alignment, VLayout, Gravity } from "./src/ui/view";
import { Color } from "./src/util/color"; import { Color } from "./src/util/color";
import { Page, Registor } from "./src/ui/page"; import { Panel, Registor } from "./src/ui/panel";
export * from "./src/ui/view" export * from "./src/ui/view"
export * from "./src/ui/page" export * from "./src/ui/panel"
export * from "./src/util/color" export * from "./src/util/color"
const v = new Text const v = new Text
v.width = 20 v.width = 20
v.height = 30 v.height = 30
@ -20,10 +19,11 @@ console.log(v.toModel())
const layout = new VLayout const layout = new VLayout
layout.space = 10 layout.space = 10
console.log(layout.viewId)
console.log(layout.toModel()) console.log(layout.toModel())
@Registor // @Registor
class MyPage extends Page { class MyPage extends Panel {
build(): import("./src/ui/view").View { build(): import("./src/ui/view").View {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }

View File

@ -5,7 +5,7 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"dev": "tsc -p .&& node ./build/index.js", "dev": "tsc -p .&& rollup -c && node ./bundle/bundle.js",
"build": "tsc -p . && rollup -c " "build": "tsc -p . && rollup -c "
}, },
"repository": { "repository": {

View File

@ -14,7 +14,7 @@ export default [
sourceMap: true, sourceMap: true,
plugins: [ plugins: [
resolve({ jsnext: true, main: true }), resolve({ jsnext: true, main: true }),
// commonjs() commonjs()
] ]
}, },
{ {

View File

@ -1,12 +1,12 @@
import { Page } from '../ui/page' import { Panel } from '../ui/panel'
import { View } from '../ui/view' import { View } from '../ui/view'
export interface Driver { export interface Driver {
/** /**
* Create and destory page * Create and destory page
*/ */
createPage(): Page createPage(): Panel
destoryPage(): Page destoryPage(): Panel
/** /**
* Page lifecycle * Page lifecycle
@ -21,3 +21,8 @@ export interface Driver {
*/ */
dispatchBuild(): View dispatchBuild(): View
} }
export interface Responser {
constructor(): void
respond(action: string, extra: any): void
}

View File

@ -10,11 +10,11 @@ export function Registor<T extends { new(...args: any[]): {} }>(constructor: T)
} }
export abstract class Page { export abstract class Panel {
onCreate(): void { } onCreate() { }
onDestory(): void { } onDestory() { }
onShow(): void { } onShow() { }
onHidden(): void { } onHidden() { }
abstract build(): View abstract build(): View
@ -22,15 +22,16 @@ export abstract class Page {
/** /**
* Native Call * Native Call
*/ */
private __onCreate__(): void { private __onCreate__() {
Reflect.defineMetadata(Symbol.for("context"), context, Reflect.getPrototypeOf(context))
this.onCreate() this.onCreate()
} }
private __onDestory__(): void { private __onDestory__() {
this.onDestory() this.onDestory()
} }
private __onShow__(): void { private __onShow__() {
this.onShow() this.onShow()
} }
@ -41,4 +42,8 @@ export abstract class Page {
private __build__(): View { private __build__(): View {
return this.build() return this.build()
} }
private __responed__(viewId: string, action: string, args: any) {
}
} }

View File

@ -1,6 +1,7 @@
import { Color, GradientColor } from "../util/color" import { Color, GradientColor } from "../util/color"
import { Modeling, Model } from "../util/types"; import { Modeling, Model } from "../util/types";
import "reflect-metadata" import "reflect-metadata"
import { uniqueId } from "../util/uniqueId";
export function Property(target: Object, propKey: string) { export function Property(target: Object, propKey: string) {
Reflect.defineMetadata(propKey, true, target) Reflect.defineMetadata(propKey, true, target)
@ -33,6 +34,13 @@ export abstract class View implements Modeling {
@Property @Property
alpha?: number alpha?: number
@Property
hidden?: boolean
@Property
viewId = uniqueId('ViewId')
constructor() { constructor() {
return new Proxy(this, { return new Proxy(this, {
get: (target, p) => { get: (target, p) => {
@ -92,7 +100,11 @@ export abstract class View implements Modeling {
} }
toModel() { toModel() {
return this.__dirty_props__ || {} return {
id: this.viewId,
type: this.constructor.name,
props: this.__dirty_props__,
}
} }
@Property @Property