import { useRef } from "react";
/**
 * This hook allows for easier declaration of events and unsubscribers
 */
export default function useEvents() {
    const _eventSUbscriptionsMap = useRef({});
    const subscriber = (e, cb) => {
        if (!_eventSUbscriptionsMap.current[e])
            _eventSUbscriptionsMap.current[e] = [];
        _eventSUbscriptionsMap.current[e].push(cb);
        return () => {
            const arr = _eventSUbscriptionsMap.current[e];
            arr.splice(arr.indexOf(cb), 1);
        };
    };
    const dispatcher = (eventName, ...args) => {
        const subscriptions = _eventSUbscriptionsMap.current[eventName] || [];
        subscriptions.forEach((cb) => cb(...args));
    };
    return {
        subscriber,
        dispatcher,
    };
}
//# sourceMappingURL=useEvents.js.map