@wordpress/hooks
Version:
WordPress hooks library.
38 lines (34 loc) • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
/**
* Internal dependencies
*/
/**
*
* Returns whether any handlers are attached for the given hookName and optional namespace.
*/
/**
* Returns a function which, when invoked, will return whether any handlers are
* attached to a particular hook.
*
* @param hooks Hooks instance.
* @param storeKey
*
* @return Function that returns whether any handlers are
* attached to a particular hook and optional namespace.
*/
function createHasHook(hooks, storeKey) {
return function hasHook(hookName, namespace) {
const hooksStore = hooks[storeKey];
// Use the namespace if provided.
if ('undefined' !== typeof namespace) {
return hookName in hooksStore && hooksStore[hookName].handlers.some(hook => hook.namespace === namespace);
}
return hookName in hooksStore;
};
}
var _default = exports.default = createHasHook;
//# sourceMappingURL=createHasHook.js.map