@wordpress/hooks
Version:
WordPress hooks library.
32 lines (29 loc) • 900 B
JavaScript
/**
* 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;
};
}
export default createHasHook;
//# sourceMappingURL=createHasHook.js.map