use-app-events
Version:
Event system for global communication in vanilla JavaScript and React.
32 lines (31 loc) • 1.03 kB
JavaScript
import p from "../broadcast/api/broadcastMessage.js";
import v from "../broadcast/api/createMessage.js";
import r from "../lib/heap.js";
import c from "../lib/options.js";
const G = (u) => {
const {
debug: l,
scopeKey: g
} = u || {};
function f(o, a, h = c.broadcast) {
l ?? c.debug;
let d;
Array.isArray(o) ? d = o : d = [o], d.forEach((s) => {
const t = /* @__PURE__ */ new Set();
r.eventListeners.forEach((e) => {
if (e.eventType === s) {
const n = t.has(e.eventGroupId), i = e.shouldBeCalledOnce && e.hasBeenCalled;
if (n || i)
return;
e.hasBeenCalled = !0, e.eventGroupId && (e.shouldBeCalledOnce && t.add(e.eventGroupId), e.callback(s, a)), e.eventGroupId || e.callback(a);
}
}), r.eventListeners.forEach((e) => {
e.shouldBeCalledOnce && e.eventGroupId && t.has(e.eventGroupId) && (e.hasBeenCalled = !0);
}), h && p(v(s, a));
});
}
return f;
};
export {
G as base_createNotifyEventListeners
};