All files / common/dist subscribe.js

88.89% Statements 16/18
90% Branches 9/10
80% Functions 4/5
88.89% Lines 16/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  9x 9x 9x 9x   9x 1x 8x 8x 8x 8x   9x   1x   1x 1x 1x           9x  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.triggerHandlers = exports.subscribeEvent = void 0;
var utils_1 = require("@mito/utils");
var handlers = {};
function subscribeEvent(handler) {
    if (!handler || utils_1.getFlag(handler.type))
        return false;
    utils_1.setFlag(handler.type, true);
    handlers[handler.type] = handlers[handler.type] || [];
    handlers[handler.type].push(handler.callback);
    return true;
}
exports.subscribeEvent = subscribeEvent;
function triggerHandlers(type, data) {
    Iif (!type || !handlers[type])
        return;
    handlers[type].forEach(function (callback) {
        utils_1.nativeTryCatch(function () {
            callback(data);
        }, function (e) {
            utils_1.logger.error("\u91CD\u5199\u4E8B\u4EF6triggerHandlers\u7684\u56DE\u8C03\u51FD\u6570\u53D1\u751F\u9519\u8BEF\nType:" + type + "\nName: " + utils_1.getFunctionName(callback) + "\nError: " + e);
        });
    });
}
exports.triggerHandlers = triggerHandlers;
//# sourceMappingURL=subscribe.js.map