@wordpress/hooks
Version:
WordPress hooks library.
8 lines (7 loc) • 987 B
Source Map (JSON)
{
"version": 3,
"sources": ["../src/createCurrentHook.ts"],
"sourcesContent": ["import type { Hooks, StoreKey } from './types';\n\n/**\n * Returns a function which, when invoked, will return the name of the\n * currently running hook, or `null` if no hook of the given type is currently\n * running.\n *\n * @param hooks Hooks instance.\n * @param storeKey\n *\n * @return Function that returns the current hook name or null.\n */\nfunction createCurrentHook(\n\thooks: Hooks,\n\tstoreKey: StoreKey\n): () => string | null {\n\treturn function currentHook() {\n\t\tconst hooksStore = hooks[ storeKey ];\n\t\tconst currentArray = Array.from( hooksStore.__current );\n\t\treturn currentArray.at( -1 )?.name ?? null;\n\t};\n}\n\nexport default createCurrentHook;\n"],
"mappings": ";AAYA,SAAS,kBACR,OACA,UACsB;AACtB,SAAO,SAAS,cAAc;AAC7B,UAAM,aAAa,MAAO,QAAS;AACnC,UAAM,eAAe,MAAM,KAAM,WAAW,SAAU;AACtD,WAAO,aAAa,GAAI,EAAG,GAAG,QAAQ;AAAA,EACvC;AACD;AAEA,IAAO,4BAAQ;",
"names": []
}