Files
NapCatQQ/.pnpm-store/v3/files/e6/0c80425da09b6c37bec6e6c1d70ba5db2e98863f722c26feed8c8fc52253cd9a34e34047caa391141a59dad120d315a82e5b82c2355b63a006616bf2000c81
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

59 lines
1.7 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.EventEmitter = void 0;
var _tslib = require("tslib");
var _react = require("react");
var EventEmitter = exports.EventEmitter = /** @class */function () {
function EventEmitter() {
var _this = this;
this.subscriptions = new Set();
this.emit = function (val) {
var e_1, _a;
try {
for (var _b = (0, _tslib.__values)(_this.subscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
var subscription = _c.value;
subscription(val);
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
} finally {
if (e_1) throw e_1.error;
}
}
};
this.useSubscription = function (callback) {
// eslint-disable-next-line react-hooks/rules-of-hooks
var callbackRef = (0, _react.useRef)(undefined);
callbackRef.current = callback;
// eslint-disable-next-line react-hooks/rules-of-hooks
(0, _react.useEffect)(function () {
function subscription(val) {
if (callbackRef.current) {
callbackRef.current(val);
}
}
_this.subscriptions.add(subscription);
return function () {
_this.subscriptions["delete"](subscription);
};
}, []);
};
}
return EventEmitter;
}();
function useEventEmitter() {
var ref = (0, _react.useRef)(undefined);
if (!ref.current) {
ref.current = new EventEmitter();
}
return ref.current;
}
var _default = exports["default"] = useEventEmitter;