feat: update modular,add mount and unmount action
This commit is contained in:
parent
6d87ad8433
commit
3ed8628dbb
@ -1,14 +1,27 @@
|
|||||||
import { Module, Color, Gravity, Group, layoutConfig, LayoutSpec, ModularPanel, Panel, scroller, text, vlayout, modal, hlayout, Text, ClassType, HLayout, View, VLayout, Provider, loge } from "doric";
|
import { Module, Color, Gravity, Group, layoutConfig, LayoutSpec, ModularPanel, scroller, text, vlayout, hlayout, Text, HLayout, View, VLayout, Provider, stack, } from "doric";
|
||||||
import { CounterPage } from "./Counter";
|
import { CounterPage } from "./Counter";
|
||||||
|
|
||||||
let moduleId = 0
|
let moduleId = 0
|
||||||
|
|
||||||
class ReceivedMessage {
|
class ReceivedMessage {
|
||||||
received: string[] = []
|
received: string[] = []
|
||||||
|
mounted: Record<string, boolean> = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SingleModule extends Module {
|
class SingleModule extends Module {
|
||||||
myId = ++moduleId
|
myId = ++moduleId
|
||||||
|
|
||||||
|
onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
this.provider?.observe(ReceivedMessage).addObserver((state => {
|
||||||
|
if (state?.mounted[this.name()] === false) {
|
||||||
|
this.unmount()
|
||||||
|
} else {
|
||||||
|
this.mount()
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
name() {
|
name() {
|
||||||
return `${this.constructor.name}#${this.myId}`
|
return `${this.constructor.name}#${this.myId}`
|
||||||
}
|
}
|
||||||
@ -46,6 +59,19 @@ class SingleModule extends Module {
|
|||||||
text: this.discription(),
|
text: this.discription(),
|
||||||
textColor: Color.WHITE,
|
textColor: Color.WHITE,
|
||||||
}),
|
}),
|
||||||
|
text({
|
||||||
|
text: "Unmount",
|
||||||
|
textSize: 12,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
onClick: () => {
|
||||||
|
this.provider?.observe(ReceivedMessage)?.update(state => {
|
||||||
|
if (state) {
|
||||||
|
state.mounted[this.name()] = false
|
||||||
|
}
|
||||||
|
return state
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}),
|
||||||
...this.buildExtraContent(),
|
...this.buildExtraContent(),
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
@ -340,6 +366,28 @@ class ScrollableHorizontalModule extends GroupModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ResetModule extends SingleModule {
|
||||||
|
discription() {
|
||||||
|
return "This module reset all modules to mounted."
|
||||||
|
}
|
||||||
|
|
||||||
|
buildExtraContent() {
|
||||||
|
return [
|
||||||
|
text({
|
||||||
|
text: "Reset",
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
onClick: () => {
|
||||||
|
this.provider?.observe(ReceivedMessage).update(state => {
|
||||||
|
if (state) {
|
||||||
|
state.mounted = {}
|
||||||
|
}
|
||||||
|
return state
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
class ModularDemo extends ModularPanel {
|
class ModularDemo extends ModularPanel {
|
||||||
@ -355,6 +403,7 @@ class ModularDemo extends ModularPanel {
|
|||||||
ScrollableVerticalModule,
|
ScrollableVerticalModule,
|
||||||
ScrollableHorizontalModule,
|
ScrollableHorizontalModule,
|
||||||
CounterPage,
|
CounterPage,
|
||||||
|
ResetModule,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
setupShelf(root: Group) {
|
setupShelf(root: Group) {
|
||||||
|
@ -3655,7 +3655,9 @@ var __extends = (undefined && undefined.__extends) || (function () {
|
|||||||
var Module = /** @class */ (function (_super) {
|
var Module = /** @class */ (function (_super) {
|
||||||
__extends(Module, _super);
|
__extends(Module, _super);
|
||||||
function Module() {
|
function Module() {
|
||||||
return _super !== null && _super.apply(this, arguments) || this;
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
_this.unmounted = false;
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
Object.defineProperty(Module.prototype, "provider", {
|
Object.defineProperty(Module.prototype, "provider", {
|
||||||
get: function () {
|
get: function () {
|
||||||
@ -3668,13 +3670,68 @@ var Module = /** @class */ (function (_super) {
|
|||||||
enumerable: false,
|
enumerable: false,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
Module.prototype.mount = function () {
|
||||||
|
var _a;
|
||||||
|
if (this.unmounted) {
|
||||||
|
this.unmounted = false;
|
||||||
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.onStructureChanged(this, true);
|
||||||
|
this.onMounted();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Module.prototype.unmount = function () {
|
||||||
|
var _a;
|
||||||
|
if (!this.unmounted) {
|
||||||
|
this.unmounted = true;
|
||||||
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.onStructureChanged(this, false);
|
||||||
|
this.onUnmounted();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Object.defineProperty(Module.prototype, "mounted", {
|
||||||
|
get: function () {
|
||||||
|
return !this.unmounted;
|
||||||
|
},
|
||||||
|
enumerable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
/**
|
||||||
|
* Dispatch message to other modules.
|
||||||
|
* @param message which is sent out
|
||||||
|
*/
|
||||||
Module.prototype.dispatchMessage = function (message) {
|
Module.prototype.dispatchMessage = function (message) {
|
||||||
var _a;
|
var _a;
|
||||||
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.dispatchMessage(message);
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.dispatchMessage(message);
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* Dispatched messages can be received by override this method.
|
||||||
|
* @param message recevied message
|
||||||
|
*/
|
||||||
Module.prototype.onMessage = function (message) { };
|
Module.prototype.onMessage = function (message) { };
|
||||||
|
/**
|
||||||
|
* Called when this module is mounted
|
||||||
|
*/
|
||||||
|
Module.prototype.onMounted = function () { };
|
||||||
|
/**
|
||||||
|
* Called when this module is unmounted
|
||||||
|
*/
|
||||||
|
Module.prototype.onUnmounted = function () { };
|
||||||
return Module;
|
return Module;
|
||||||
}(Panel));
|
}(Panel));
|
||||||
|
var VMModule = /** @class */ (function (_super) {
|
||||||
|
__extends(VMModule, _super);
|
||||||
|
function VMModule() {
|
||||||
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
}
|
||||||
|
VMModule.prototype.getViewModel = function () {
|
||||||
|
return this.vm;
|
||||||
|
};
|
||||||
|
VMModule.prototype.build = function (root) {
|
||||||
|
this.vh = new (this.getViewHolderClass());
|
||||||
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
||||||
|
this.vm.context = this.context;
|
||||||
|
this.vm.attach(root);
|
||||||
|
};
|
||||||
|
return VMModule;
|
||||||
|
}(Module));
|
||||||
var ModularPanel = /** @class */ (function (_super) {
|
var ModularPanel = /** @class */ (function (_super) {
|
||||||
__extends(ModularPanel, _super);
|
__extends(ModularPanel, _super);
|
||||||
function ModularPanel() {
|
function ModularPanel() {
|
||||||
@ -3696,16 +3753,38 @@ var ModularPanel = /** @class */ (function (_super) {
|
|||||||
this.onMessage(message);
|
this.onMessage(message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Object.defineProperty(ModularPanel.prototype, "mountedModules", {
|
||||||
|
get: function () {
|
||||||
|
return this.modules.filter(function (e) { return !(e instanceof Module) || e.mounted; });
|
||||||
|
},
|
||||||
|
enumerable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
ModularPanel.prototype.onMessage = function (message) {
|
ModularPanel.prototype.onMessage = function (message) {
|
||||||
this.modules.forEach(function (e) {
|
this.mountedModules.forEach(function (e) {
|
||||||
if (e instanceof Module) {
|
if (e instanceof Module) {
|
||||||
e.onMessage(message);
|
e.onMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
ModularPanel.prototype.onStructureChanged = function (module, mounted) {
|
||||||
|
var _this = this;
|
||||||
|
if (this.superPanel) {
|
||||||
|
this.superPanel.onStructureChanged(module, mounted);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!!!this.scheduledRebuild) {
|
||||||
|
this.scheduledRebuild = setTimeout(function () {
|
||||||
|
_this.scheduledRebuild = undefined;
|
||||||
|
_this.getRootView().children.length = 0;
|
||||||
|
_this.build(_this.getRootView());
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
ModularPanel.prototype.build = function (root) {
|
ModularPanel.prototype.build = function (root) {
|
||||||
var groupView = this.setupShelf(root);
|
var groupView = this.setupShelf(root);
|
||||||
this.modules.forEach(function (e) {
|
this.mountedModules.forEach(function (e) {
|
||||||
Reflect.set(e, "__root__", groupView);
|
Reflect.set(e, "__root__", groupView);
|
||||||
e.build(groupView);
|
e.build(groupView);
|
||||||
});
|
});
|
||||||
@ -3713,32 +3792,32 @@ var ModularPanel = /** @class */ (function (_super) {
|
|||||||
ModularPanel.prototype.onCreate = function () {
|
ModularPanel.prototype.onCreate = function () {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
_super.prototype.onCreate.call(this);
|
_super.prototype.onCreate.call(this);
|
||||||
this.modules.forEach(function (e) {
|
this.mountedModules.forEach(function (e) {
|
||||||
e.context = _this.context;
|
e.context = _this.context;
|
||||||
e.onCreate();
|
e.onCreate();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
ModularPanel.prototype.onDestroy = function () {
|
ModularPanel.prototype.onDestroy = function () {
|
||||||
_super.prototype.onDestroy.call(this);
|
_super.prototype.onDestroy.call(this);
|
||||||
this.modules.forEach(function (e) {
|
this.mountedModules.forEach(function (e) {
|
||||||
e.onDestroy();
|
e.onDestroy();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
ModularPanel.prototype.onShow = function () {
|
ModularPanel.prototype.onShow = function () {
|
||||||
_super.prototype.onShow.call(this);
|
_super.prototype.onShow.call(this);
|
||||||
this.modules.forEach(function (e) {
|
this.mountedModules.forEach(function (e) {
|
||||||
e.onShow();
|
e.onShow();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
ModularPanel.prototype.onHidden = function () {
|
ModularPanel.prototype.onHidden = function () {
|
||||||
_super.prototype.onHidden.call(this);
|
_super.prototype.onHidden.call(this);
|
||||||
this.modules.forEach(function (e) {
|
this.mountedModules.forEach(function (e) {
|
||||||
e.onHidden();
|
e.onHidden();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
ModularPanel.prototype.onRenderFinished = function () {
|
ModularPanel.prototype.onRenderFinished = function () {
|
||||||
_super.prototype.onRenderFinished.call(this);
|
_super.prototype.onRenderFinished.call(this);
|
||||||
this.modules.forEach(function (e) {
|
this.mountedModules.forEach(function (e) {
|
||||||
e.onRenderFinished();
|
e.onRenderFinished();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -3792,6 +3871,7 @@ exports.TOP = TOP;
|
|||||||
exports.Text = Text;
|
exports.Text = Text;
|
||||||
exports.TranslationAnimation = TranslationAnimation;
|
exports.TranslationAnimation = TranslationAnimation;
|
||||||
exports.VLayout = VLayout;
|
exports.VLayout = VLayout;
|
||||||
|
exports.VMModule = VMModule;
|
||||||
exports.VMPanel = VMPanel;
|
exports.VMPanel = VMPanel;
|
||||||
exports.View = View;
|
exports.View = View;
|
||||||
exports.ViewComponent = ViewComponent;
|
exports.ViewComponent = ViewComponent;
|
||||||
|
@ -2822,6 +2822,10 @@ class VMPanel extends Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Module extends Panel {
|
class Module extends Panel {
|
||||||
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
this.unmounted = false;
|
||||||
|
}
|
||||||
get provider() {
|
get provider() {
|
||||||
var _a;
|
var _a;
|
||||||
return this.__provider || ((_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.provider);
|
return this.__provider || ((_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.provider);
|
||||||
@ -2829,11 +2833,57 @@ class Module extends Panel {
|
|||||||
set provider(provider) {
|
set provider(provider) {
|
||||||
this.__provider = provider;
|
this.__provider = provider;
|
||||||
}
|
}
|
||||||
|
mount() {
|
||||||
|
var _a;
|
||||||
|
if (this.unmounted) {
|
||||||
|
this.unmounted = false;
|
||||||
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.onStructureChanged(this, true);
|
||||||
|
this.onMounted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unmount() {
|
||||||
|
var _a;
|
||||||
|
if (!this.unmounted) {
|
||||||
|
this.unmounted = true;
|
||||||
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.onStructureChanged(this, false);
|
||||||
|
this.onUnmounted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get mounted() {
|
||||||
|
return !this.unmounted;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Dispatch message to other modules.
|
||||||
|
* @param message which is sent out
|
||||||
|
*/
|
||||||
dispatchMessage(message) {
|
dispatchMessage(message) {
|
||||||
var _a;
|
var _a;
|
||||||
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.dispatchMessage(message);
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.dispatchMessage(message);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Dispatched messages can be received by override this method.
|
||||||
|
* @param message recevied message
|
||||||
|
*/
|
||||||
onMessage(message) { }
|
onMessage(message) { }
|
||||||
|
/**
|
||||||
|
* Called when this module is mounted
|
||||||
|
*/
|
||||||
|
onMounted() { }
|
||||||
|
/**
|
||||||
|
* Called when this module is unmounted
|
||||||
|
*/
|
||||||
|
onUnmounted() { }
|
||||||
|
}
|
||||||
|
class VMModule extends Module {
|
||||||
|
getViewModel() {
|
||||||
|
return this.vm;
|
||||||
|
}
|
||||||
|
build(root) {
|
||||||
|
this.vh = new (this.getViewHolderClass());
|
||||||
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
||||||
|
this.vm.context = this.context;
|
||||||
|
this.vm.attach(root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class ModularPanel extends Module {
|
class ModularPanel extends Module {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -2854,48 +2904,65 @@ class ModularPanel extends Module {
|
|||||||
this.onMessage(message);
|
this.onMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get mountedModules() {
|
||||||
|
return this.modules.filter(e => !(e instanceof Module) || e.mounted);
|
||||||
|
}
|
||||||
onMessage(message) {
|
onMessage(message) {
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
if (e instanceof Module) {
|
if (e instanceof Module) {
|
||||||
e.onMessage(message);
|
e.onMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
onStructureChanged(module, mounted) {
|
||||||
|
if (this.superPanel) {
|
||||||
|
this.superPanel.onStructureChanged(module, mounted);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!!!this.scheduledRebuild) {
|
||||||
|
this.scheduledRebuild = setTimeout(() => {
|
||||||
|
this.scheduledRebuild = undefined;
|
||||||
|
this.getRootView().children.length = 0;
|
||||||
|
this.build(this.getRootView());
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
build(root) {
|
build(root) {
|
||||||
const groupView = this.setupShelf(root);
|
const groupView = this.setupShelf(root);
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
Reflect.set(e, "__root__", groupView);
|
Reflect.set(e, "__root__", groupView);
|
||||||
e.build(groupView);
|
e.build(groupView);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onCreate() {
|
onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.context = this.context;
|
e.context = this.context;
|
||||||
e.onCreate();
|
e.onCreate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onDestroy() {
|
onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onDestroy();
|
e.onDestroy();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onShow() {
|
onShow() {
|
||||||
super.onShow();
|
super.onShow();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onShow();
|
e.onShow();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onHidden() {
|
onHidden() {
|
||||||
super.onHidden();
|
super.onHidden();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onHidden();
|
e.onHidden();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onRenderFinished() {
|
onRenderFinished() {
|
||||||
super.onRenderFinished();
|
super.onRenderFinished();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onRenderFinished();
|
e.onRenderFinished();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2948,6 +3015,7 @@ exports.TOP = TOP;
|
|||||||
exports.Text = Text;
|
exports.Text = Text;
|
||||||
exports.TranslationAnimation = TranslationAnimation;
|
exports.TranslationAnimation = TranslationAnimation;
|
||||||
exports.VLayout = VLayout;
|
exports.VLayout = VLayout;
|
||||||
|
exports.VMModule = VMModule;
|
||||||
exports.VMPanel = VMPanel;
|
exports.VMPanel = VMPanel;
|
||||||
exports.View = View;
|
exports.View = View;
|
||||||
exports.ViewComponent = ViewComponent;
|
exports.ViewComponent = ViewComponent;
|
||||||
|
@ -4343,6 +4343,10 @@ class VMPanel extends Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Module extends Panel {
|
class Module extends Panel {
|
||||||
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
this.unmounted = false;
|
||||||
|
}
|
||||||
get provider() {
|
get provider() {
|
||||||
var _a;
|
var _a;
|
||||||
return this.__provider || ((_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.provider);
|
return this.__provider || ((_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.provider);
|
||||||
@ -4350,11 +4354,57 @@ class Module extends Panel {
|
|||||||
set provider(provider) {
|
set provider(provider) {
|
||||||
this.__provider = provider;
|
this.__provider = provider;
|
||||||
}
|
}
|
||||||
|
mount() {
|
||||||
|
var _a;
|
||||||
|
if (this.unmounted) {
|
||||||
|
this.unmounted = false;
|
||||||
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.onStructureChanged(this, true);
|
||||||
|
this.onMounted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unmount() {
|
||||||
|
var _a;
|
||||||
|
if (!this.unmounted) {
|
||||||
|
this.unmounted = true;
|
||||||
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.onStructureChanged(this, false);
|
||||||
|
this.onUnmounted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get mounted() {
|
||||||
|
return !this.unmounted;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Dispatch message to other modules.
|
||||||
|
* @param message which is sent out
|
||||||
|
*/
|
||||||
dispatchMessage(message) {
|
dispatchMessage(message) {
|
||||||
var _a;
|
var _a;
|
||||||
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.dispatchMessage(message);
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.dispatchMessage(message);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Dispatched messages can be received by override this method.
|
||||||
|
* @param message recevied message
|
||||||
|
*/
|
||||||
onMessage(message) { }
|
onMessage(message) { }
|
||||||
|
/**
|
||||||
|
* Called when this module is mounted
|
||||||
|
*/
|
||||||
|
onMounted() { }
|
||||||
|
/**
|
||||||
|
* Called when this module is unmounted
|
||||||
|
*/
|
||||||
|
onUnmounted() { }
|
||||||
|
}
|
||||||
|
class VMModule extends Module {
|
||||||
|
getViewModel() {
|
||||||
|
return this.vm;
|
||||||
|
}
|
||||||
|
build(root) {
|
||||||
|
this.vh = new (this.getViewHolderClass());
|
||||||
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
||||||
|
this.vm.context = this.context;
|
||||||
|
this.vm.attach(root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class ModularPanel extends Module {
|
class ModularPanel extends Module {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -4375,48 +4425,65 @@ class ModularPanel extends Module {
|
|||||||
this.onMessage(message);
|
this.onMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get mountedModules() {
|
||||||
|
return this.modules.filter(e => !(e instanceof Module) || e.mounted);
|
||||||
|
}
|
||||||
onMessage(message) {
|
onMessage(message) {
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
if (e instanceof Module) {
|
if (e instanceof Module) {
|
||||||
e.onMessage(message);
|
e.onMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
onStructureChanged(module, mounted) {
|
||||||
|
if (this.superPanel) {
|
||||||
|
this.superPanel.onStructureChanged(module, mounted);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!!!this.scheduledRebuild) {
|
||||||
|
this.scheduledRebuild = setTimeout(() => {
|
||||||
|
this.scheduledRebuild = undefined;
|
||||||
|
this.getRootView().children.length = 0;
|
||||||
|
this.build(this.getRootView());
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
build(root) {
|
build(root) {
|
||||||
const groupView = this.setupShelf(root);
|
const groupView = this.setupShelf(root);
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
Reflect.set(e, "__root__", groupView);
|
Reflect.set(e, "__root__", groupView);
|
||||||
e.build(groupView);
|
e.build(groupView);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onCreate() {
|
onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.context = this.context;
|
e.context = this.context;
|
||||||
e.onCreate();
|
e.onCreate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onDestroy() {
|
onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onDestroy();
|
e.onDestroy();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onShow() {
|
onShow() {
|
||||||
super.onShow();
|
super.onShow();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onShow();
|
e.onShow();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onHidden() {
|
onHidden() {
|
||||||
super.onHidden();
|
super.onHidden();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onHidden();
|
e.onHidden();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onRenderFinished() {
|
onRenderFinished() {
|
||||||
super.onRenderFinished();
|
super.onRenderFinished();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onRenderFinished();
|
e.onRenderFinished();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -4710,6 +4777,7 @@ exports.TOP = TOP;
|
|||||||
exports.Text = Text;
|
exports.Text = Text;
|
||||||
exports.TranslationAnimation = TranslationAnimation;
|
exports.TranslationAnimation = TranslationAnimation;
|
||||||
exports.VLayout = VLayout;
|
exports.VLayout = VLayout;
|
||||||
|
exports.VMModule = VMModule;
|
||||||
exports.VMPanel = VMPanel;
|
exports.VMPanel = VMPanel;
|
||||||
exports.View = View;
|
exports.View = View;
|
||||||
exports.ViewComponent = ViewComponent;
|
exports.ViewComponent = ViewComponent;
|
||||||
|
29
doric-js/index.d.ts
vendored
29
doric-js/index.d.ts
vendored
@ -1423,21 +1423,50 @@ declare module 'doric/lib/src/pattern/modular' {
|
|||||||
import { Panel } from "doric/lib/src/ui/panel";
|
import { Panel } from "doric/lib/src/ui/panel";
|
||||||
import { Group } from "doric/lib/src/ui/view";
|
import { Group } from "doric/lib/src/ui/view";
|
||||||
import { ClassType } from "doric/lib/src/util/types";
|
import { ClassType } from "doric/lib/src/util/types";
|
||||||
|
import { ViewHolder, ViewModel } from "doric/lib/src/pattern/mvvm";
|
||||||
import { Provider } from "doric/lib/src/pattern/provider";
|
import { Provider } from "doric/lib/src/pattern/provider";
|
||||||
export abstract class Module extends Panel {
|
export abstract class Module extends Panel {
|
||||||
superPanel?: ModularPanel;
|
superPanel?: ModularPanel;
|
||||||
__provider?: Provider;
|
__provider?: Provider;
|
||||||
get provider(): Provider | undefined;
|
get provider(): Provider | undefined;
|
||||||
set provider(provider: Provider | undefined);
|
set provider(provider: Provider | undefined);
|
||||||
|
mount(): void;
|
||||||
|
unmount(): void;
|
||||||
|
get mounted(): boolean;
|
||||||
|
/**
|
||||||
|
* Dispatch message to other modules.
|
||||||
|
* @param message which is sent out
|
||||||
|
*/
|
||||||
dispatchMessage(message: any): void;
|
dispatchMessage(message: any): void;
|
||||||
|
/**
|
||||||
|
* Dispatched messages can be received by override this method.
|
||||||
|
* @param message recevied message
|
||||||
|
*/
|
||||||
onMessage(message: any): void;
|
onMessage(message: any): void;
|
||||||
|
/**
|
||||||
|
* Called when this module is mounted
|
||||||
|
*/
|
||||||
|
onMounted(): void;
|
||||||
|
/**
|
||||||
|
* Called when this module is unmounted
|
||||||
|
*/
|
||||||
|
onUnmounted(): void;
|
||||||
|
}
|
||||||
|
export abstract class VMModule<M extends Object, V extends ViewHolder> extends Module {
|
||||||
|
abstract getViewModelClass(): ClassType<ViewModel<M, V>>;
|
||||||
|
abstract getState(): M;
|
||||||
|
abstract getViewHolderClass(): ClassType<V>;
|
||||||
|
getViewModel(): ViewModel<M, V> | undefined;
|
||||||
|
build(root: Group): void;
|
||||||
}
|
}
|
||||||
export abstract class ModularPanel extends Module {
|
export abstract class ModularPanel extends Module {
|
||||||
constructor();
|
constructor();
|
||||||
abstract setupModules(): ClassType<Panel>[];
|
abstract setupModules(): ClassType<Panel>[];
|
||||||
abstract setupShelf(root: Group): Group;
|
abstract setupShelf(root: Group): Group;
|
||||||
dispatchMessage(message: any): void;
|
dispatchMessage(message: any): void;
|
||||||
|
get mountedModules(): Panel[];
|
||||||
onMessage(message: any): void;
|
onMessage(message: any): void;
|
||||||
|
onStructureChanged(module: Module, mounted: boolean): void;
|
||||||
build(root: Group): void;
|
build(root: Group): void;
|
||||||
onCreate(): void;
|
onCreate(): void;
|
||||||
onDestroy(): void;
|
onDestroy(): void;
|
||||||
|
33
doric-js/lib/src/pattern/modular.d.ts
vendored
33
doric-js/lib/src/pattern/modular.d.ts
vendored
@ -1,22 +1,55 @@
|
|||||||
import { Panel } from "../ui/panel";
|
import { Panel } from "../ui/panel";
|
||||||
import { Group } from "../ui/view";
|
import { Group } from "../ui/view";
|
||||||
import { ClassType } from "../util/types";
|
import { ClassType } from "../util/types";
|
||||||
|
import { ViewHolder, ViewModel } from "./mvvm";
|
||||||
import { Provider } from "./provider";
|
import { Provider } from "./provider";
|
||||||
export declare abstract class Module extends Panel {
|
export declare abstract class Module extends Panel {
|
||||||
superPanel?: ModularPanel;
|
superPanel?: ModularPanel;
|
||||||
__provider?: Provider;
|
__provider?: Provider;
|
||||||
get provider(): Provider | undefined;
|
get provider(): Provider | undefined;
|
||||||
set provider(provider: Provider | undefined);
|
set provider(provider: Provider | undefined);
|
||||||
|
private unmounted;
|
||||||
|
mount(): void;
|
||||||
|
unmount(): void;
|
||||||
|
get mounted(): boolean;
|
||||||
|
/**
|
||||||
|
* Dispatch message to other modules.
|
||||||
|
* @param message which is sent out
|
||||||
|
*/
|
||||||
dispatchMessage(message: any): void;
|
dispatchMessage(message: any): void;
|
||||||
|
/**
|
||||||
|
* Dispatched messages can be received by override this method.
|
||||||
|
* @param message recevied message
|
||||||
|
*/
|
||||||
onMessage(message: any): void;
|
onMessage(message: any): void;
|
||||||
|
/**
|
||||||
|
* Called when this module is mounted
|
||||||
|
*/
|
||||||
|
onMounted(): void;
|
||||||
|
/**
|
||||||
|
* Called when this module is unmounted
|
||||||
|
*/
|
||||||
|
onUnmounted(): void;
|
||||||
|
}
|
||||||
|
export declare abstract class VMModule<M extends Object, V extends ViewHolder> extends Module {
|
||||||
|
private vm?;
|
||||||
|
private vh?;
|
||||||
|
abstract getViewModelClass(): ClassType<ViewModel<M, V>>;
|
||||||
|
abstract getState(): M;
|
||||||
|
abstract getViewHolderClass(): ClassType<V>;
|
||||||
|
getViewModel(): ViewModel<M, V> | undefined;
|
||||||
|
build(root: Group): void;
|
||||||
}
|
}
|
||||||
export declare abstract class ModularPanel extends Module {
|
export declare abstract class ModularPanel extends Module {
|
||||||
private modules;
|
private modules;
|
||||||
|
private scheduledRebuild?;
|
||||||
constructor();
|
constructor();
|
||||||
abstract setupModules(): ClassType<Panel>[];
|
abstract setupModules(): ClassType<Panel>[];
|
||||||
abstract setupShelf(root: Group): Group;
|
abstract setupShelf(root: Group): Group;
|
||||||
dispatchMessage(message: any): void;
|
dispatchMessage(message: any): void;
|
||||||
|
get mountedModules(): Panel[];
|
||||||
onMessage(message: any): void;
|
onMessage(message: any): void;
|
||||||
|
onStructureChanged(module: Module, mounted: boolean): void;
|
||||||
build(root: Group): void;
|
build(root: Group): void;
|
||||||
onCreate(): void;
|
onCreate(): void;
|
||||||
onDestroy(): void;
|
onDestroy(): void;
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import { Panel } from "../ui/panel";
|
import { Panel } from "../ui/panel";
|
||||||
export class Module extends Panel {
|
export class Module extends Panel {
|
||||||
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
this.unmounted = false;
|
||||||
|
}
|
||||||
get provider() {
|
get provider() {
|
||||||
var _a;
|
var _a;
|
||||||
return this.__provider || ((_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.provider);
|
return this.__provider || ((_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.provider);
|
||||||
@ -7,11 +11,57 @@ export class Module extends Panel {
|
|||||||
set provider(provider) {
|
set provider(provider) {
|
||||||
this.__provider = provider;
|
this.__provider = provider;
|
||||||
}
|
}
|
||||||
|
mount() {
|
||||||
|
var _a;
|
||||||
|
if (this.unmounted) {
|
||||||
|
this.unmounted = false;
|
||||||
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.onStructureChanged(this, true);
|
||||||
|
this.onMounted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unmount() {
|
||||||
|
var _a;
|
||||||
|
if (!this.unmounted) {
|
||||||
|
this.unmounted = true;
|
||||||
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.onStructureChanged(this, false);
|
||||||
|
this.onUnmounted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get mounted() {
|
||||||
|
return !this.unmounted;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Dispatch message to other modules.
|
||||||
|
* @param message which is sent out
|
||||||
|
*/
|
||||||
dispatchMessage(message) {
|
dispatchMessage(message) {
|
||||||
var _a;
|
var _a;
|
||||||
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.dispatchMessage(message);
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.dispatchMessage(message);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Dispatched messages can be received by override this method.
|
||||||
|
* @param message recevied message
|
||||||
|
*/
|
||||||
onMessage(message) { }
|
onMessage(message) { }
|
||||||
|
/**
|
||||||
|
* Called when this module is mounted
|
||||||
|
*/
|
||||||
|
onMounted() { }
|
||||||
|
/**
|
||||||
|
* Called when this module is unmounted
|
||||||
|
*/
|
||||||
|
onUnmounted() { }
|
||||||
|
}
|
||||||
|
export class VMModule extends Module {
|
||||||
|
getViewModel() {
|
||||||
|
return this.vm;
|
||||||
|
}
|
||||||
|
build(root) {
|
||||||
|
this.vh = new (this.getViewHolderClass());
|
||||||
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
||||||
|
this.vm.context = this.context;
|
||||||
|
this.vm.attach(root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export class ModularPanel extends Module {
|
export class ModularPanel extends Module {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -32,48 +82,65 @@ export class ModularPanel extends Module {
|
|||||||
this.onMessage(message);
|
this.onMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get mountedModules() {
|
||||||
|
return this.modules.filter(e => !(e instanceof Module) || e.mounted);
|
||||||
|
}
|
||||||
onMessage(message) {
|
onMessage(message) {
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
if (e instanceof Module) {
|
if (e instanceof Module) {
|
||||||
e.onMessage(message);
|
e.onMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
onStructureChanged(module, mounted) {
|
||||||
|
if (this.superPanel) {
|
||||||
|
this.superPanel.onStructureChanged(module, mounted);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!!!this.scheduledRebuild) {
|
||||||
|
this.scheduledRebuild = setTimeout(() => {
|
||||||
|
this.scheduledRebuild = undefined;
|
||||||
|
this.getRootView().children.length = 0;
|
||||||
|
this.build(this.getRootView());
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
build(root) {
|
build(root) {
|
||||||
const groupView = this.setupShelf(root);
|
const groupView = this.setupShelf(root);
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
Reflect.set(e, "__root__", groupView);
|
Reflect.set(e, "__root__", groupView);
|
||||||
e.build(groupView);
|
e.build(groupView);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onCreate() {
|
onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.context = this.context;
|
e.context = this.context;
|
||||||
e.onCreate();
|
e.onCreate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onDestroy() {
|
onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onDestroy();
|
e.onDestroy();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onShow() {
|
onShow() {
|
||||||
super.onShow();
|
super.onShow();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onShow();
|
e.onShow();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onHidden() {
|
onHidden() {
|
||||||
super.onHidden();
|
super.onHidden();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onHidden();
|
e.onHidden();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onRenderFinished() {
|
onRenderFinished() {
|
||||||
super.onRenderFinished();
|
super.onRenderFinished();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onRenderFinished();
|
e.onRenderFinished();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Panel } from "../ui/panel"
|
import { Panel } from "../ui/panel"
|
||||||
import { Group } from "../ui/view"
|
import { Group } from "../ui/view"
|
||||||
import { ClassType } from "../util/types"
|
import { ClassType } from "../util/types"
|
||||||
|
import { ViewHolder, ViewModel } from "./mvvm"
|
||||||
import { Provider } from "./provider"
|
import { Provider } from "./provider"
|
||||||
|
|
||||||
export abstract class Module extends Panel {
|
export abstract class Module extends Panel {
|
||||||
@ -16,15 +17,77 @@ export abstract class Module extends Panel {
|
|||||||
this.__provider = provider
|
this.__provider = provider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private unmounted = false
|
||||||
|
|
||||||
|
mount() {
|
||||||
|
if (this.unmounted) {
|
||||||
|
this.unmounted = false
|
||||||
|
this.superPanel?.onStructureChanged(this, true)
|
||||||
|
this.onMounted()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unmount() {
|
||||||
|
if (!this.unmounted) {
|
||||||
|
this.unmounted = true
|
||||||
|
this.superPanel?.onStructureChanged(this, false)
|
||||||
|
this.onUnmounted()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get mounted() {
|
||||||
|
return !this.unmounted
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch message to other modules.
|
||||||
|
* @param message which is sent out
|
||||||
|
*/
|
||||||
dispatchMessage(message: any) {
|
dispatchMessage(message: any) {
|
||||||
this.superPanel?.dispatchMessage(message)
|
this.superPanel?.dispatchMessage(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatched messages can be received by override this method.
|
||||||
|
* @param message recevied message
|
||||||
|
*/
|
||||||
onMessage(message: any) { }
|
onMessage(message: any) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when this module is mounted
|
||||||
|
*/
|
||||||
|
onMounted() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when this module is unmounted
|
||||||
|
*/
|
||||||
|
onUnmounted() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class VMModule<M extends Object, V extends ViewHolder> extends Module {
|
||||||
|
private vm?: ViewModel<M, V>
|
||||||
|
private vh?: V
|
||||||
|
abstract getViewModelClass(): ClassType<ViewModel<M, V>>
|
||||||
|
|
||||||
|
abstract getState(): M
|
||||||
|
|
||||||
|
abstract getViewHolderClass(): ClassType<V>
|
||||||
|
|
||||||
|
getViewModel() {
|
||||||
|
return this.vm
|
||||||
|
}
|
||||||
|
|
||||||
|
build(root: Group): void {
|
||||||
|
this.vh = new (this.getViewHolderClass())
|
||||||
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh)
|
||||||
|
this.vm.context = this.context
|
||||||
|
this.vm.attach(root)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class ModularPanel extends Module {
|
export abstract class ModularPanel extends Module {
|
||||||
private modules: Panel[]
|
private modules: Panel[]
|
||||||
|
private scheduledRebuild?: NodeJS.Timeout
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
@ -49,18 +112,35 @@ export abstract class ModularPanel extends Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get mountedModules() {
|
||||||
|
return this.modules.filter(e => !(e instanceof Module) || e.mounted)
|
||||||
|
}
|
||||||
|
|
||||||
onMessage(message: any) {
|
onMessage(message: any) {
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
if (e instanceof Module) {
|
if (e instanceof Module) {
|
||||||
e.onMessage(message)
|
e.onMessage(message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onStructureChanged(module: Module, mounted: boolean) {
|
||||||
|
if (this.superPanel) {
|
||||||
|
this.superPanel.onStructureChanged(module, mounted)
|
||||||
|
} else {
|
||||||
|
if (!!!this.scheduledRebuild) {
|
||||||
|
this.scheduledRebuild = setTimeout(() => {
|
||||||
|
this.scheduledRebuild = undefined
|
||||||
|
this.getRootView().children.length = 0
|
||||||
|
this.build(this.getRootView())
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
build(root: Group) {
|
build(root: Group) {
|
||||||
const groupView = this.setupShelf(root)
|
const groupView = this.setupShelf(root)
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
Reflect.set(e, "__root__", groupView)
|
Reflect.set(e, "__root__", groupView)
|
||||||
e.build(groupView)
|
e.build(groupView)
|
||||||
})
|
})
|
||||||
@ -68,7 +148,7 @@ export abstract class ModularPanel extends Module {
|
|||||||
|
|
||||||
onCreate() {
|
onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.context = this.context
|
e.context = this.context
|
||||||
e.onCreate()
|
e.onCreate()
|
||||||
})
|
})
|
||||||
@ -76,28 +156,28 @@ export abstract class ModularPanel extends Module {
|
|||||||
|
|
||||||
onDestroy() {
|
onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onDestroy()
|
e.onDestroy()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
super.onShow()
|
super.onShow()
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onShow()
|
e.onShow()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onHidden() {
|
onHidden() {
|
||||||
super.onHidden()
|
super.onHidden()
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onHidden()
|
e.onHidden()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onRenderFinished() {
|
onRenderFinished() {
|
||||||
super.onRenderFinished()
|
super.onRenderFinished()
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onRenderFinished()
|
e.onRenderFinished()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
82
doric-web/dist/index.js
vendored
82
doric-web/dist/index.js
vendored
@ -4397,6 +4397,10 @@ class VMPanel extends Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Module extends Panel {
|
class Module extends Panel {
|
||||||
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
this.unmounted = false;
|
||||||
|
}
|
||||||
get provider() {
|
get provider() {
|
||||||
var _a;
|
var _a;
|
||||||
return this.__provider || ((_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.provider);
|
return this.__provider || ((_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.provider);
|
||||||
@ -4404,11 +4408,57 @@ class Module extends Panel {
|
|||||||
set provider(provider) {
|
set provider(provider) {
|
||||||
this.__provider = provider;
|
this.__provider = provider;
|
||||||
}
|
}
|
||||||
|
mount() {
|
||||||
|
var _a;
|
||||||
|
if (this.unmounted) {
|
||||||
|
this.unmounted = false;
|
||||||
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.onStructureChanged(this, true);
|
||||||
|
this.onMounted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unmount() {
|
||||||
|
var _a;
|
||||||
|
if (!this.unmounted) {
|
||||||
|
this.unmounted = true;
|
||||||
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.onStructureChanged(this, false);
|
||||||
|
this.onUnmounted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get mounted() {
|
||||||
|
return !this.unmounted;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Dispatch message to other modules.
|
||||||
|
* @param message which is sent out
|
||||||
|
*/
|
||||||
dispatchMessage(message) {
|
dispatchMessage(message) {
|
||||||
var _a;
|
var _a;
|
||||||
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.dispatchMessage(message);
|
(_a = this.superPanel) === null || _a === void 0 ? void 0 : _a.dispatchMessage(message);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Dispatched messages can be received by override this method.
|
||||||
|
* @param message recevied message
|
||||||
|
*/
|
||||||
onMessage(message) { }
|
onMessage(message) { }
|
||||||
|
/**
|
||||||
|
* Called when this module is mounted
|
||||||
|
*/
|
||||||
|
onMounted() { }
|
||||||
|
/**
|
||||||
|
* Called when this module is unmounted
|
||||||
|
*/
|
||||||
|
onUnmounted() { }
|
||||||
|
}
|
||||||
|
class VMModule extends Module {
|
||||||
|
getViewModel() {
|
||||||
|
return this.vm;
|
||||||
|
}
|
||||||
|
build(root) {
|
||||||
|
this.vh = new (this.getViewHolderClass());
|
||||||
|
this.vm = new (this.getViewModelClass())(this.getState(), this.vh);
|
||||||
|
this.vm.context = this.context;
|
||||||
|
this.vm.attach(root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class ModularPanel extends Module {
|
class ModularPanel extends Module {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -4429,48 +4479,65 @@ class ModularPanel extends Module {
|
|||||||
this.onMessage(message);
|
this.onMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get mountedModules() {
|
||||||
|
return this.modules.filter(e => !(e instanceof Module) || e.mounted);
|
||||||
|
}
|
||||||
onMessage(message) {
|
onMessage(message) {
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
if (e instanceof Module) {
|
if (e instanceof Module) {
|
||||||
e.onMessage(message);
|
e.onMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
onStructureChanged(module, mounted) {
|
||||||
|
if (this.superPanel) {
|
||||||
|
this.superPanel.onStructureChanged(module, mounted);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!!!this.scheduledRebuild) {
|
||||||
|
this.scheduledRebuild = setTimeout(() => {
|
||||||
|
this.scheduledRebuild = undefined;
|
||||||
|
this.getRootView().children.length = 0;
|
||||||
|
this.build(this.getRootView());
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
build(root) {
|
build(root) {
|
||||||
const groupView = this.setupShelf(root);
|
const groupView = this.setupShelf(root);
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
Reflect.set(e, "__root__", groupView);
|
Reflect.set(e, "__root__", groupView);
|
||||||
e.build(groupView);
|
e.build(groupView);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onCreate() {
|
onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.context = this.context;
|
e.context = this.context;
|
||||||
e.onCreate();
|
e.onCreate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onDestroy() {
|
onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onDestroy();
|
e.onDestroy();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onShow() {
|
onShow() {
|
||||||
super.onShow();
|
super.onShow();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onShow();
|
e.onShow();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onHidden() {
|
onHidden() {
|
||||||
super.onHidden();
|
super.onHidden();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onHidden();
|
e.onHidden();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onRenderFinished() {
|
onRenderFinished() {
|
||||||
super.onRenderFinished();
|
super.onRenderFinished();
|
||||||
this.modules.forEach(e => {
|
this.mountedModules.forEach(e => {
|
||||||
e.onRenderFinished();
|
e.onRenderFinished();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -4523,6 +4590,7 @@ exports.TOP = TOP;
|
|||||||
exports.Text = Text;
|
exports.Text = Text;
|
||||||
exports.TranslationAnimation = TranslationAnimation;
|
exports.TranslationAnimation = TranslationAnimation;
|
||||||
exports.VLayout = VLayout;
|
exports.VLayout = VLayout;
|
||||||
|
exports.VMModule = VMModule;
|
||||||
exports.VMPanel = VMPanel;
|
exports.VMPanel = VMPanel;
|
||||||
exports.View = View;
|
exports.View = View;
|
||||||
exports.ViewComponent = ViewComponent;
|
exports.ViewComponent = ViewComponent;
|
||||||
|
2
doric-web/dist/index.js.map
vendored
2
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user