feat: update modular,add mount and unmount action

This commit is contained in:
pengfei.zhou
2021-05-18 11:41:18 +08:00
committed by osborn
parent 6d87ad8433
commit 3ed8628dbb
10 changed files with 604 additions and 62 deletions

View File

@@ -3655,7 +3655,9 @@ var __extends = (undefined && undefined.__extends) || (function () {
var Module = /** @class */ (function (_super) {
__extends(Module, _super);
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", {
get: function () {
@@ -3668,13 +3670,68 @@ var Module = /** @class */ (function (_super) {
enumerable: false,
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) {
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
*/
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;
}(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) {
__extends(ModularPanel, _super);
function ModularPanel() {
@@ -3696,16 +3753,38 @@ var ModularPanel = /** @class */ (function (_super) {
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) {
this.modules.forEach(function (e) {
this.mountedModules.forEach(function (e) {
if (e instanceof Module) {
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) {
var groupView = this.setupShelf(root);
this.modules.forEach(function (e) {
this.mountedModules.forEach(function (e) {
Reflect.set(e, "__root__", groupView);
e.build(groupView);
});
@@ -3713,32 +3792,32 @@ var ModularPanel = /** @class */ (function (_super) {
ModularPanel.prototype.onCreate = function () {
var _this = this;
_super.prototype.onCreate.call(this);
this.modules.forEach(function (e) {
this.mountedModules.forEach(function (e) {
e.context = _this.context;
e.onCreate();
});
};
ModularPanel.prototype.onDestroy = function () {
_super.prototype.onDestroy.call(this);
this.modules.forEach(function (e) {
this.mountedModules.forEach(function (e) {
e.onDestroy();
});
};
ModularPanel.prototype.onShow = function () {
_super.prototype.onShow.call(this);
this.modules.forEach(function (e) {
this.mountedModules.forEach(function (e) {
e.onShow();
});
};
ModularPanel.prototype.onHidden = function () {
_super.prototype.onHidden.call(this);
this.modules.forEach(function (e) {
this.mountedModules.forEach(function (e) {
e.onHidden();
});
};
ModularPanel.prototype.onRenderFinished = function () {
_super.prototype.onRenderFinished.call(this);
this.modules.forEach(function (e) {
this.mountedModules.forEach(function (e) {
e.onRenderFinished();
});
};
@@ -3792,6 +3871,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;

View File

@@ -2822,6 +2822,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);
@@ -2829,11 +2833,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() {
@@ -2854,48 +2904,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();
});
}
@@ -2948,6 +3015,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;

View File

@@ -4343,6 +4343,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);
@@ -4350,11 +4354,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() {
@@ -4375,48 +4425,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();
});
}
@@ -4710,6 +4777,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;