feat: update modular,add mount and unmount action
This commit is contained in:
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 {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.unmounted = false;
|
||||
}
|
||||
get provider() {
|
||||
var _a;
|
||||
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) {
|
||||
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) {
|
||||
var _a;
|
||||
(_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) { }
|
||||
/**
|
||||
* 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 {
|
||||
constructor() {
|
||||
@@ -4429,48 +4479,65 @@ class ModularPanel extends Module {
|
||||
this.onMessage(message);
|
||||
}
|
||||
}
|
||||
get mountedModules() {
|
||||
return this.modules.filter(e => !(e instanceof Module) || e.mounted);
|
||||
}
|
||||
onMessage(message) {
|
||||
this.modules.forEach(e => {
|
||||
this.mountedModules.forEach(e => {
|
||||
if (e instanceof Module) {
|
||||
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) {
|
||||
const groupView = this.setupShelf(root);
|
||||
this.modules.forEach(e => {
|
||||
this.mountedModules.forEach(e => {
|
||||
Reflect.set(e, "__root__", groupView);
|
||||
e.build(groupView);
|
||||
});
|
||||
}
|
||||
onCreate() {
|
||||
super.onCreate();
|
||||
this.modules.forEach(e => {
|
||||
this.mountedModules.forEach(e => {
|
||||
e.context = this.context;
|
||||
e.onCreate();
|
||||
});
|
||||
}
|
||||
onDestroy() {
|
||||
super.onDestroy();
|
||||
this.modules.forEach(e => {
|
||||
this.mountedModules.forEach(e => {
|
||||
e.onDestroy();
|
||||
});
|
||||
}
|
||||
onShow() {
|
||||
super.onShow();
|
||||
this.modules.forEach(e => {
|
||||
this.mountedModules.forEach(e => {
|
||||
e.onShow();
|
||||
});
|
||||
}
|
||||
onHidden() {
|
||||
super.onHidden();
|
||||
this.modules.forEach(e => {
|
||||
this.mountedModules.forEach(e => {
|
||||
e.onHidden();
|
||||
});
|
||||
}
|
||||
onRenderFinished() {
|
||||
super.onRenderFinished();
|
||||
this.modules.forEach(e => {
|
||||
this.mountedModules.forEach(e => {
|
||||
e.onRenderFinished();
|
||||
});
|
||||
}
|
||||
@@ -4523,6 +4590,7 @@ exports.TOP = TOP;
|
||||
exports.Text = Text;
|
||||
exports.TranslationAnimation = TranslationAnimation;
|
||||
exports.VLayout = VLayout;
|
||||
exports.VMModule = VMModule;
|
||||
exports.VMPanel = VMPanel;
|
||||
exports.View = View;
|
||||
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