@crossed/sheet
Version:
A Cross Platform(Android & iOS) ActionSheet with a robust and flexible api, native performance and zero dependency code for react native. Create anything you want inside ActionSheet.
40 lines (39 loc) • 1.06 kB
JavaScript
class EventManager {
_registry;
constructor() {
this._registry = /* @__PURE__ */ new Map();
}
unsubscribeAll() {
this._registry.clear();
}
subscribe(name, handler, once = false) {
if (!name || !handler)
throw new Error("name and handler are required.");
this._registry.set(handler, { name, once });
return { unsubscribe: () => this.unsubscribe(name, handler) };
}
unsubscribe(_name, handler) {
return this._registry.delete(handler);
}
publish(name, ...args) {
this._registry.forEach((props, handler) => {
if (props.name === name)
handler(...args);
if (props.once)
this._registry.delete(handler);
});
}
remove(...names) {
this._registry.forEach((props, handler) => {
if (names.includes(props.name))
this._registry.delete(handler);
});
}
}
var eventmanager_default = EventManager;
const actionSheetEventManager = new EventManager();
export {
actionSheetEventManager,
eventmanager_default as default
};
//# sourceMappingURL=eventmanager.js.map