UNPKG

@procore/core-react

Version:
22 lines 831 B
import React from 'react'; export var useEventRegistry = function useEventRegistry() { var registry = React.useRef({}); var addListener = React.useCallback(function (e, cb) { var _registry$current$e; var currentCbs = (_registry$current$e = registry.current[e]) !== null && _registry$current$e !== void 0 ? _registry$current$e : []; currentCbs.push(cb); registry.current[e] = currentCbs; return function () { var _registry$current$e2; var cbs = (_registry$current$e2 = registry.current[e]) !== null && _registry$current$e2 !== void 0 ? _registry$current$e2 : []; registry.current[e] = cbs.filter(function (callback) { return callback !== cb; }); }; }, []); return { registry: registry, addListener: addListener }; }; //# sourceMappingURL=EventRegistry.js.map