@wordpress/hooks
Version:
WordPress hooks library.
8 lines (7 loc) • 1.57 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/createDoingHook.ts"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { Hooks, StoreKey } from './types';\n\n/**\n * Returns whether a hook is currently being executed.\n *\n */\nexport type DoingHook = (\n\t/**\n\t * The name of the hook to check for.\n\t * If omitted, will check for any hook being executed.\n\t */ hookName?: string\n) => boolean;\n\n/**\n * Returns a function which, when invoked, will return whether a hook is\n * currently being executed.\n *\n * @param hooks Hooks instance.\n * @param storeKey\n *\n * @return Function that returns whether a hook is currently\n * being executed.\n */\nfunction createDoingHook( hooks: Hooks, storeKey: StoreKey ): DoingHook {\n\treturn function doingHook( hookName ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\t// If the hookName was not passed, check for any current hook.\n\t\tif ( 'undefined' === typeof hookName ) {\n\t\t\treturn hooksStore.__current.size > 0;\n\t\t}\n\n\t\t// Find if the `hookName` hook is in `__current`.\n\t\treturn Array.from( hooksStore.__current ).some(\n\t\t\t( hook ) => hook.name === hookName\n\t\t);\n\t};\n}\n\nexport default createDoingHook;\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BA,SAAS,gBAAiB,OAAc,UAAgC;AACvE,SAAO,SAAS,UAAW,UAAW;AACrC,UAAM,aAAa,MAAO,QAAS;AAGnC,QAAK,gBAAgB,OAAO,UAAW;AACtC,aAAO,WAAW,UAAU,OAAO;AAAA,IACpC;AAGA,WAAO,MAAM,KAAM,WAAW,SAAU,EAAE;AAAA,MACzC,CAAE,SAAU,KAAK,SAAS;AAAA,IAC3B;AAAA,EACD;AACD;AAEA,IAAO,0BAAQ;",
"names": []
}