@pisell/pisellos
Version:
一个可扩展的前端模块化SDK框架,支持插件系统
90 lines (88 loc) • 2.97 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/modules/BaseModule.ts
var BaseModule_exports = {};
__export(BaseModule_exports, {
BaseModule: () => BaseModule
});
module.exports = __toCommonJS(BaseModule_exports);
var BaseModule = class {
constructor(name, version) {
this.defaultName = "baseModule";
this.defaultVersion = "1.0.0";
this.isSolution = false;
this.name = name || this.defaultName;
this.version = version || this.defaultVersion;
}
destroy() {
this.core.effects.offByModuleDestroy(this.name);
this.core.unregisterModule(this);
}
// 提供统一的缓存 module 里的数据的方法
checkSaveCache({
cacheId,
fatherModule,
store,
cacheKey
}) {
const window = this.core.getPlugin("window");
if (cacheId) {
if (fatherModule) {
const currentCacheData = window.sessionStorage.getItem(fatherModule);
let currentCacheDataObj = JSON.parse(currentCacheData || "{}");
if (!currentCacheData || !currentCacheDataObj[cacheId]) {
currentCacheDataObj = {
[cacheId]: {
[this.name]: {}
}
};
}
if (!currentCacheDataObj[cacheId][this.name]) {
currentCacheDataObj[cacheId][this.name] = {};
}
cacheKey.forEach((key) => {
currentCacheDataObj[cacheId][this.name][key] = store == null ? void 0 : store[key];
});
window.sessionStorage.setItem(
fatherModule,
JSON.stringify(currentCacheDataObj)
);
} else {
let currentCacheData = window.sessionStorage.getItem(cacheId);
let currentCacheDataObj = JSON.parse(currentCacheData || "{}");
if (!currentCacheDataObj) {
currentCacheDataObj = {};
}
if (!currentCacheDataObj[this.name]) {
currentCacheDataObj[this.name] = {};
}
cacheKey.forEach((key) => {
currentCacheDataObj[this.name][key] = store[key];
});
window.sessionStorage.setItem(
cacheId,
JSON.stringify(currentCacheDataObj)
);
}
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BaseModule
});