/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/hooks/src/createDoingHook.ts
40 строк
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import type { Hooks, StoreKey } from './types'; /** * Returns whether a hook is currently being executed. * */ export type DoingHook = ( /** * The name of the hook to check for. * If omitted, will check for any hook being executed. */ hookName?: string ) => boolean; /** * Returns a function which, when invoked, will return whether a hook is * currently being executed. * * @param hooks Hooks instance. * @param storeKey * * @return Function that returns whether a hook is currently * being executed. */ function createDoingHook( hooks: Hooks, storeKey: StoreKey ): DoingHook { return function doingHook( hookName ) { const hooksStore = hooks[ storeKey ]; // If the hookName was not passed, check for any current hook. if ( 'undefined' === typeof hookName ) { return hooksStore.__current.size > 0; } // Find if the `hookName` hook is in `__current`. return Array.from( hooksStore.__current ).some( ( hook ) => hook.name === hookName ); }; } export default createDoingHook;