Update: add some comments
This commit is contained in:
parent
3ed8628dbb
commit
d7c5de4b90
@ -1,9 +1,9 @@
|
|||||||
import { Module, Color, Gravity, Group, layoutConfig, LayoutSpec, ModularPanel, scroller, text, vlayout, hlayout, Text, HLayout, View, VLayout, Provider, stack, } from "doric";
|
import { Module, Color, Gravity, Group, layoutConfig, LayoutSpec, ModularPanel, scroller, text, vlayout, hlayout, Text, HLayout, View, VLayout, Provider, stack, loge, } from "doric";
|
||||||
import { CounterPage } from "./Counter";
|
import { CounterPage } from "./Counter";
|
||||||
|
|
||||||
let moduleId = 0
|
let moduleId = 0
|
||||||
|
|
||||||
class ReceivedMessage {
|
class ProvidedData {
|
||||||
received: string[] = []
|
received: string[] = []
|
||||||
mounted: Record<string, boolean> = {}
|
mounted: Record<string, boolean> = {}
|
||||||
}
|
}
|
||||||
@ -13,7 +13,7 @@ class SingleModule extends Module {
|
|||||||
|
|
||||||
onCreate() {
|
onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
this.provider?.observe(ReceivedMessage).addObserver((state => {
|
this.provider?.observe(ProvidedData).addObserver((state => {
|
||||||
if (state?.mounted[this.name()] === false) {
|
if (state?.mounted[this.name()] === false) {
|
||||||
this.unmount()
|
this.unmount()
|
||||||
} else {
|
} else {
|
||||||
@ -48,7 +48,7 @@ class SingleModule extends Module {
|
|||||||
textSize: 20,
|
textSize: 20,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
this.dispatchMessage(`Hello from ${this.name()}`)
|
this.dispatchMessage(`Hello from ${this.name()}`)
|
||||||
this.provider?.observe(ReceivedMessage)?.update(state => {
|
this.provider?.observe(ProvidedData)?.update(state => {
|
||||||
state?.received.push(this.name())
|
state?.received.push(this.name())
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
@ -64,7 +64,7 @@ class SingleModule extends Module {
|
|||||||
textSize: 12,
|
textSize: 12,
|
||||||
textColor: Color.WHITE,
|
textColor: Color.WHITE,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
this.provider?.observe(ReceivedMessage)?.update(state => {
|
this.provider?.observe(ProvidedData)?.update(state => {
|
||||||
if (state) {
|
if (state) {
|
||||||
state.mounted[this.name()] = false
|
state.mounted[this.name()] = false
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ abstract class GroupModule extends ModularPanel {
|
|||||||
textSize: 20,
|
textSize: 20,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
this.dispatchMessage(`Hello from ${this.name()}`)
|
this.dispatchMessage(`Hello from ${this.name()}`)
|
||||||
this.provider?.observe(ReceivedMessage)?.update(state => {
|
this.provider?.observe(ProvidedData)?.update(state => {
|
||||||
state?.received.push(this.name())
|
state?.received.push(this.name())
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
@ -192,7 +192,7 @@ class ProviderWatcher extends SingleModule {
|
|||||||
|
|
||||||
onCreate() {
|
onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
this.provider?.observe(ReceivedMessage)?.addObserver((ret) => {
|
this.provider?.observe(ProvidedData)?.addObserver((ret) => {
|
||||||
this.contentLabel!.text = ret?.received?.join("\n")
|
this.contentLabel!.text = ret?.received?.join("\n")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -326,6 +326,9 @@ class ScrollableVerticalModule extends GroupModule {
|
|||||||
SingleModule,
|
SingleModule,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
onCreate() {
|
||||||
|
this.provider?.remove(ProvidedData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ScrollableHorizontalModule extends GroupModule {
|
class ScrollableHorizontalModule extends GroupModule {
|
||||||
@ -377,7 +380,7 @@ class ResetModule extends SingleModule {
|
|||||||
text: "Reset",
|
text: "Reset",
|
||||||
textColor: Color.WHITE,
|
textColor: Color.WHITE,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
this.provider?.observe(ReceivedMessage).update(state => {
|
this.provider?.observe(ProvidedData).update(state => {
|
||||||
if (state) {
|
if (state) {
|
||||||
state.mounted = {}
|
state.mounted = {}
|
||||||
}
|
}
|
||||||
@ -391,9 +394,14 @@ class ResetModule extends SingleModule {
|
|||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
class ModularDemo extends ModularPanel {
|
class ModularDemo extends ModularPanel {
|
||||||
setupModules() {
|
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
this.provider = new Provider
|
this.provider = new Provider
|
||||||
this.provider.provide(new ReceivedMessage)
|
this.provider.provide(new ProvidedData)
|
||||||
|
}
|
||||||
|
|
||||||
|
setupModules() {
|
||||||
return [
|
return [
|
||||||
SingleModule,
|
SingleModule,
|
||||||
ProviderWatcher,
|
ProviderWatcher,
|
||||||
|
7
doric-js/index.d.ts
vendored
7
doric-js/index.d.ts
vendored
@ -1461,7 +1461,14 @@ declare module 'doric/lib/src/pattern/modular' {
|
|||||||
}
|
}
|
||||||
export abstract class ModularPanel extends Module {
|
export abstract class ModularPanel extends Module {
|
||||||
constructor();
|
constructor();
|
||||||
|
/**
|
||||||
|
* @returns Class list of current submodules
|
||||||
|
*/
|
||||||
abstract setupModules(): ClassType<Panel>[];
|
abstract setupModules(): ClassType<Panel>[];
|
||||||
|
/**
|
||||||
|
* @param root Current module's rootview
|
||||||
|
* @returns provided for submodules as their rootview
|
||||||
|
*/
|
||||||
abstract setupShelf(root: Group): Group;
|
abstract setupShelf(root: Group): Group;
|
||||||
dispatchMessage(message: any): void;
|
dispatchMessage(message: any): void;
|
||||||
get mountedModules(): Panel[];
|
get mountedModules(): Panel[];
|
||||||
|
7
doric-js/lib/src/pattern/modular.d.ts
vendored
7
doric-js/lib/src/pattern/modular.d.ts
vendored
@ -44,7 +44,14 @@ export declare abstract class ModularPanel extends Module {
|
|||||||
private modules;
|
private modules;
|
||||||
private scheduledRebuild?;
|
private scheduledRebuild?;
|
||||||
constructor();
|
constructor();
|
||||||
|
/**
|
||||||
|
* @returns Class list of current submodules
|
||||||
|
*/
|
||||||
abstract setupModules(): ClassType<Panel>[];
|
abstract setupModules(): ClassType<Panel>[];
|
||||||
|
/**
|
||||||
|
* @param root Current module's rootview
|
||||||
|
* @returns provided for submodules as their rootview
|
||||||
|
*/
|
||||||
abstract setupShelf(root: Group): Group;
|
abstract setupShelf(root: Group): Group;
|
||||||
dispatchMessage(message: any): void;
|
dispatchMessage(message: any): void;
|
||||||
get mountedModules(): Panel[];
|
get mountedModules(): Panel[];
|
||||||
|
@ -100,8 +100,15 @@ export abstract class ModularPanel extends Module {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns Class list of current submodules
|
||||||
|
*/
|
||||||
abstract setupModules(): ClassType<Panel>[]
|
abstract setupModules(): ClassType<Panel>[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param root Current module's rootview
|
||||||
|
* @returns provided for submodules as their rootview
|
||||||
|
*/
|
||||||
abstract setupShelf(root: Group): Group
|
abstract setupShelf(root: Group): Group
|
||||||
|
|
||||||
dispatchMessage(message: any) {
|
dispatchMessage(message: any) {
|
||||||
|
Reference in New Issue
Block a user