use global define to touch context

This commit is contained in:
pengfei.zhou 2019-07-17 16:04:45 +08:00
parent 9cd607e822
commit 86b048b3b4
4 changed files with 34 additions and 3 deletions

View File

@ -1,5 +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";
export * from "./src/ui/view"
export * from "./src/ui/page"
export * from "./src/util/color"
const v = new Text const v = new Text
v.width = 20 v.width = 20
@ -15,6 +21,11 @@ console.log(v.toModel())
const layout = new VLayout const layout = new VLayout
layout.space = 10 layout.space = 10
console.log(layout.toModel()) console.log(layout.toModel())
export * from "./src/ui/view"
export * from "./src/ui/page" @Registor
export * from "./src/util/color" class MyPage extends Page {
build(): import("./src/ui/view").View {
throw new Error("Method not implemented.");
}
}
console.log('end')

View File

@ -0,0 +1,6 @@
import { Context } from "./sandbox";
declare global {
const context: Context
}
export { }

View File

@ -77,6 +77,7 @@ export function jsCallReject(contextId: string, callbackId: string, args?: any)
} }
export class Context { export class Context {
holder: any
id: string id: string
callbacks: Map<string, { resolve: Function, reject: Function }> = new Map callbacks: Map<string, { resolve: Function, reject: Function }> = new Map
constructor(id: string) { constructor(id: string) {
@ -93,6 +94,9 @@ export class Context {
}) })
}) })
} }
registor(instance: Object) {
this.holder = instance
}
} }

View File

@ -1,4 +1,14 @@
import { View } from "./view"; import { View } from "./view";
import { } from '../runtime/global'
export function Registor<T extends { new(...args: any[]): {} }>(constructor: T) {
const ret = class extends constructor {
context = context
}
context.registor(new ret)
return ret
}
export abstract class Page { export abstract class Page {
onCreate(): void { } onCreate(): void { }