fastlion-amis
Version:
一种MIS页面生成工具
53 lines (52 loc) • 1.95 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventSub = exports.EventEnum = void 0;
var helper_1 = require("./helper");
var EventEnum;
(function (EventEnum) {
EventEnum["ClearVistiMap"] = "ClearVistiMap";
EventEnum["ShowVistiMap"] = "ShowVistiMap";
EventEnum["ClearMappingAcahe"] = "ClearMappingAcahe";
EventEnum["DomPrint"] = "DetailPrint";
EventEnum["ClearSelectCache"] = "ClearSelectCache";
})(EventEnum = exports.EventEnum || (exports.EventEnum = {}));
var Sub = /** @class */ (function () {
function Sub() {
this.subs = {};
}
Sub.prototype.on = function (eventName, cb) {
var _a;
var id = 'SUB-' + (0, helper_1.uuidv4)();
if (this.subs[eventName]) {
this.subs[eventName][id] = cb;
}
else {
this.subs[eventName] = (_a = {}, _a[id] = cb, _a);
}
return id;
};
Sub.prototype.off = function (eventName, id) {
var _a, _b, _c, _d;
if (id === void 0) { id = ''; }
if (id && ((_b = (_a = this.subs) === null || _a === void 0 ? void 0 : _a[eventName]) === null || _b === void 0 ? void 0 : _b[id])) {
(_d = (_c = this.subs) === null || _c === void 0 ? void 0 : _c[eventName]) === null || _d === void 0 ? true : delete _d[id];
}
else if (!id)
delete this.subs[eventName];
};
Sub.prototype.emit = function (key) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
if (this.subs[key]) {
for (var _a = 0, _b = Object.values(this.subs[key]); _a < _b.length; _a++) {
var item = _b[_a];
item.apply(void 0, args);
}
}
};
return Sub;
}());
exports.EventSub = new Sub();
//# sourceMappingURL=./utils/sub.js.map
;