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