2021-05-13 14:50:54 +08:00
|
|
|
import { Panel } from "../ui/panel"
|
|
|
|
import { Group } from "../ui/view"
|
|
|
|
import { ClassType } from "../util/types"
|
|
|
|
|
2021-05-13 16:57:21 +08:00
|
|
|
export abstract class Module extends Panel {
|
|
|
|
superPanel?: ModularPanel
|
|
|
|
|
|
|
|
dispatchMessage(message: any) {
|
|
|
|
this.superPanel?.dispatchMessage(message)
|
|
|
|
}
|
|
|
|
|
|
|
|
onMessage(message: any) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
export abstract class ModularPanel extends Module {
|
2021-05-13 14:50:54 +08:00
|
|
|
private modules: Panel[]
|
2021-05-13 16:57:21 +08:00
|
|
|
|
2021-05-13 14:50:54 +08:00
|
|
|
constructor() {
|
|
|
|
super()
|
2021-05-13 16:57:21 +08:00
|
|
|
this.modules = this.setupModules().map(e => {
|
|
|
|
const instance = new e
|
|
|
|
if (instance instanceof Module) {
|
|
|
|
instance.superPanel = this
|
|
|
|
}
|
|
|
|
return instance
|
|
|
|
})
|
2021-05-13 14:50:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract setupModules(): ClassType<Panel>[]
|
2021-05-13 16:57:21 +08:00
|
|
|
|
2021-05-13 14:50:54 +08:00
|
|
|
abstract setupShelf(root: Group): Group
|
|
|
|
|
2021-05-13 16:57:21 +08:00
|
|
|
dispatchMessage(message: any) {
|
|
|
|
if (this.superPanel) {
|
|
|
|
this.superPanel.dispatchMessage(message)
|
|
|
|
} else {
|
|
|
|
this.onMessage(message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMessage(message: any) {
|
|
|
|
this.modules.forEach(e => {
|
|
|
|
if (e instanceof Module) {
|
|
|
|
e.onMessage(message)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-13 14:50:54 +08:00
|
|
|
build(root: Group) {
|
|
|
|
const groupView = this.setupShelf(root)
|
|
|
|
this.modules.forEach(e => {
|
|
|
|
Reflect.set(e, "__root__", groupView)
|
|
|
|
e.build(groupView)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
onCreate() {
|
|
|
|
super.onCreate()
|
|
|
|
this.modules.forEach(e => {
|
2021-05-13 16:26:48 +08:00
|
|
|
e.context = this.context
|
2021-05-13 14:50:54 +08:00
|
|
|
e.onCreate()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
onDestroy() {
|
|
|
|
super.onDestroy()
|
|
|
|
this.modules.forEach(e => {
|
|
|
|
e.onDestroy()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
onShow() {
|
|
|
|
super.onShow()
|
|
|
|
this.modules.forEach(e => {
|
|
|
|
e.onShow()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
onHidden() {
|
|
|
|
super.onHidden()
|
|
|
|
this.modules.forEach(e => {
|
|
|
|
e.onHidden()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
onRenderFinished() {
|
|
|
|
super.onRenderFinished()
|
|
|
|
this.modules.forEach(e => {
|
|
|
|
e.onRenderFinished()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|