import { EventAggregator } from "oj-eventaggregator";
const ea = new EventAggregator<{
"edit": boolean,
"event": any,
"another": any,
}>()
subscribers with "*" listen to all events
ea.on("edit", editing => element.classList.toggle("is-editing", editing))
ea.once("event", (data, event) => {})
ea.onMultiple(["event", "another"], (data, event) => {})
ea.onceMultiple(["event", "another"], (data, event) => {}) // callback will get called only once
editBtn.addEventListener("click", e => ea.emit("edit", true))
ea.emitMultiple(["event", "another"], data)
const sub = ea.on("event", (data, event) => {})
sub.off()
ea.clear("event") // removes all subscribers
ea.clearMultiple(["event", "another"])
const sub = ea.on("event", (data, event) => {})
sub.pause()
// sub does not respond to "event" emits
sub.resume()
ea.pause()
// eventaggregator does not emit any events
ea.resume()