view build flow
This commit is contained in:
parent
e2537c5e9d
commit
369a488af6
@ -1,4 +1,4 @@
|
|||||||
import { Text, Alignment, Color, VLayout, Registor, Panel, log, logw, loge } from "./index"
|
import { Text, Alignment, Color, VLayout, Link, Panel, log, logw, loge } from "./index"
|
||||||
|
|
||||||
const v = new Text
|
const v = new Text
|
||||||
v.width = 20
|
v.width = 20
|
||||||
@ -30,7 +30,7 @@ setTimeout(() => {
|
|||||||
clearInterval(timerId)
|
clearInterval(timerId)
|
||||||
}, 5000)
|
}, 5000)
|
||||||
|
|
||||||
@Registor(context)
|
@Link(context)
|
||||||
export class MyPage extends Panel {
|
export class MyPage extends Panel {
|
||||||
build() {
|
build() {
|
||||||
return layout
|
return layout
|
||||||
|
3
js-framework/package-lock.json
generated
3
js-framework/package-lock.json
generated
@ -1,8 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "hego-js-framework",
|
"name": "doric-js-framework",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/estree": {
|
"@types/estree": {
|
||||||
"version": "0.0.39",
|
"version": "0.0.39",
|
||||||
|
@ -26,4 +26,4 @@
|
|||||||
"rollup-plugin-node-resolve": "^5.2.0",
|
"rollup-plugin-node-resolve": "^5.2.0",
|
||||||
"tslib": "^1.10.0"
|
"tslib": "^1.10.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { View } from "./view";
|
import { } from './../runtime/global';
|
||||||
|
import { View, Stack, Group } from "./view";
|
||||||
|
import { log } from 'util';
|
||||||
|
|
||||||
export function Registor(context: any) {
|
export function Link(context: any) {
|
||||||
return <T extends { new(...args: any[]): {} }>(constructor: T) => {
|
return <T extends { new(...args: any[]): {} }>(constructor: T) => {
|
||||||
const ret = class extends constructor {
|
const ret = class extends constructor {
|
||||||
context = context
|
context = context
|
||||||
@ -10,41 +12,91 @@ export function Registor(context: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||||
|
const originVal = descriptor.value
|
||||||
|
descriptor.value = function () {
|
||||||
|
const args = []
|
||||||
|
for (let index in arguments) {
|
||||||
|
args.push(arguments[index]);
|
||||||
|
}
|
||||||
|
Reflect.apply(Reflect.get(target, '__hookBeforeNativeCall__'), this, [])
|
||||||
|
const ret = Reflect.apply(originVal, this, args)
|
||||||
|
Reflect.apply(Reflect.get(target, '__hookAfterNativeCall__'), this, [])
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
return descriptor
|
||||||
|
}
|
||||||
|
|
||||||
|
type Frame = { width: number, height: number }
|
||||||
|
|
||||||
export abstract class Panel {
|
export abstract class Panel {
|
||||||
|
|
||||||
onCreate() { }
|
onCreate() { }
|
||||||
onDestory() { }
|
onDestory() { }
|
||||||
onShow() { }
|
onShow() { }
|
||||||
onHidden() { }
|
onHidden() { }
|
||||||
|
|
||||||
abstract build(): View
|
abstract build(rootView: Group): void
|
||||||
|
|
||||||
|
private __data__: any
|
||||||
|
private __rootView__: Group = new Stack
|
||||||
|
|
||||||
/**
|
getRootView() {
|
||||||
* Native Call
|
return this.__rootView__
|
||||||
*/
|
}
|
||||||
|
getInitData() {
|
||||||
|
return this.__data__
|
||||||
|
}
|
||||||
|
|
||||||
|
@NativeCall
|
||||||
|
private __init__(frame: Frame, data: any) {
|
||||||
|
this.__data__ = data
|
||||||
|
this.__rootView__.width = frame.width
|
||||||
|
this.__rootView__.height = frame.height
|
||||||
|
this.build(this.__rootView__)
|
||||||
|
}
|
||||||
|
|
||||||
|
@NativeCall
|
||||||
private __onCreate__() {
|
private __onCreate__() {
|
||||||
Reflect.defineMetadata(Symbol.for("context"), context, Reflect.getPrototypeOf(context))
|
|
||||||
this.onCreate()
|
this.onCreate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeCall
|
||||||
private __onDestory__() {
|
private __onDestory__() {
|
||||||
this.onDestory()
|
this.onDestory()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeCall
|
||||||
private __onShow__() {
|
private __onShow__() {
|
||||||
this.onShow()
|
this.onShow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeCall
|
||||||
private __onHidden__(): void {
|
private __onHidden__(): void {
|
||||||
this.onHidden()
|
this.onHidden()
|
||||||
}
|
}
|
||||||
|
|
||||||
private __build__(): View {
|
@NativeCall
|
||||||
return this.build()
|
private __build__() {
|
||||||
|
this.build(this.__rootView__)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeCall
|
||||||
private __responedCallback__(viewId: string, callbackId: string) {
|
private __responedCallback__(viewId: string, callbackId: string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private __hookBeforeNativeCall__() {
|
||||||
|
log('__hookBeforeNativeCall__')
|
||||||
|
}
|
||||||
|
|
||||||
|
private __hookAfterNativeCall__() {
|
||||||
|
log('__hookAfterNativeCall__')
|
||||||
|
if (this.__rootView__.isDirty()) {
|
||||||
|
const model = this.__rootView__.toModel()
|
||||||
|
log('needRefresh:' + JSON.stringify(model))
|
||||||
|
this.__rootView__.clean()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -125,7 +125,9 @@ export abstract class View implements Modeling {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isDirty() {
|
||||||
|
return Reflect.ownKeys(this.__dirty_props__).length === 0
|
||||||
|
}
|
||||||
responseCallback(id: string) {
|
responseCallback(id: string) {
|
||||||
const f = this.id2Callback(id)
|
const f = this.id2Callback(id)
|
||||||
if (f instanceof Function) {
|
if (f instanceof Function) {
|
||||||
|
Reference in New Issue
Block a user