@wordpress/hooks 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/LICENSE.md +788 -0
  3. package/README.md +66 -0
  4. package/benchmark/index.js +56 -0
  5. package/build/createAddHook.js +114 -0
  6. package/build/createAddHook.js.map +1 -0
  7. package/build/createCurrentHook.js +29 -0
  8. package/build/createCurrentHook.js.map +1 -0
  9. package/build/createDidHook.js +49 -0
  10. package/build/createDidHook.js.map +1 -0
  11. package/build/createDoingHook.js +43 -0
  12. package/build/createDoingHook.js.map +1 -0
  13. package/build/createHasHook.js +44 -0
  14. package/build/createHasHook.js.map +1 -0
  15. package/build/createHooks.js +80 -0
  16. package/build/createHooks.js.map +1 -0
  17. package/build/createRemoveHook.js +99 -0
  18. package/build/createRemoveHook.js.map +1 -0
  19. package/build/createRunHook.js +73 -0
  20. package/build/createRunHook.js.map +1 -0
  21. package/build/index.js +94 -0
  22. package/build/index.js.map +1 -0
  23. package/build/validateHookName.js +41 -0
  24. package/build/validateHookName.js.map +1 -0
  25. package/build/validateNamespace.js +34 -0
  26. package/build/validateNamespace.js.map +1 -0
  27. package/build-module/createAddHook.js +102 -0
  28. package/build-module/createAddHook.js.map +1 -0
  29. package/build-module/createCurrentHook.js +21 -0
  30. package/build-module/createCurrentHook.js.map +1 -0
  31. package/build-module/createDidHook.js +38 -0
  32. package/build-module/createDidHook.js.map +1 -0
  33. package/build-module/createDoingHook.js +35 -0
  34. package/build-module/createDoingHook.js.map +1 -0
  35. package/build-module/createHasHook.js +36 -0
  36. package/build-module/createHasHook.js.map +1 -0
  37. package/build-module/createHooks.js +60 -0
  38. package/build-module/createHooks.js.map +1 -0
  39. package/build-module/createRemoveHook.js +87 -0
  40. package/build-module/createRemoveHook.js.map +1 -0
  41. package/build-module/createRunHook.js +65 -0
  42. package/build-module/createRunHook.js.map +1 -0
  43. package/build-module/index.js +60 -0
  44. package/build-module/index.js.map +1 -0
  45. package/build-module/validateHookName.js +33 -0
  46. package/build-module/validateHookName.js.map +1 -0
  47. package/build-module/validateNamespace.js +26 -0
  48. package/build-module/validateNamespace.js.map +1 -0
  49. package/build-types/createAddHook.d.ts +25 -0
  50. package/build-types/createAddHook.d.ts.map +1 -0
  51. package/build-types/createCurrentHook.d.ts +13 -0
  52. package/build-types/createCurrentHook.d.ts.map +1 -0
  53. package/build-types/createDidHook.d.ts +25 -0
  54. package/build-types/createDidHook.d.ts.map +1 -0
  55. package/build-types/createDoingHook.d.ts +26 -0
  56. package/build-types/createDoingHook.d.ts.map +1 -0
  57. package/build-types/createHasHook.d.ts +28 -0
  58. package/build-types/createHasHook.d.ts.map +1 -0
  59. package/build-types/createHooks.d.ts +39 -0
  60. package/build-types/createHooks.d.ts.map +1 -0
  61. package/build-types/createRemoveHook.d.ts +31 -0
  62. package/build-types/createRemoveHook.d.ts.map +1 -0
  63. package/build-types/createRunHook.d.ts +15 -0
  64. package/build-types/createRunHook.d.ts.map +1 -0
  65. package/build-types/index.d.ts +88 -0
  66. package/build-types/index.d.ts.map +1 -0
  67. package/build-types/validateHookName.d.ts +12 -0
  68. package/build-types/validateHookName.d.ts.map +1 -0
  69. package/build-types/validateNamespace.d.ts +11 -0
  70. package/build-types/validateNamespace.d.ts.map +1 -0
  71. package/package.json +35 -0
  72. package/src/createAddHook.js +107 -0
  73. package/src/createCurrentHook.js +22 -0
  74. package/src/createDidHook.js +39 -0
  75. package/src/createDoingHook.js +37 -0
  76. package/src/createHasHook.js +40 -0
  77. package/src/createHooks.js +59 -0
  78. package/src/createRemoveHook.js +88 -0
  79. package/src/createRunHook.js +66 -0
  80. package/src/index.js +82 -0
  81. package/src/test/index.test.js +945 -0
  82. package/src/validateHookName.js +34 -0
  83. package/src/validateNamespace.js +27 -0
  84. package/tsconfig.json +9 -0
  85. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import validateNamespace from './validateNamespace.js';
5
+ import validateHookName from './validateHookName.js';
6
+ /**
7
+ * @callback RemoveHook
8
+ * Removes the specified callback (or all callbacks) from the hook with a given hookName
9
+ * and namespace.
10
+ *
11
+ * @param {string} hookName The name of the hook to modify.
12
+ * @param {string} namespace The unique namespace identifying the callback in the
13
+ * form `vendor/plugin/function`.
14
+ *
15
+ * @return {number | undefined} The number of callbacks removed.
16
+ */
17
+
18
+ /**
19
+ * Returns a function which, when invoked, will remove a specified hook or all
20
+ * hooks by the given name.
21
+ *
22
+ * @param {import('.').Hooks} hooks Hooks instance.
23
+ * @param {import('.').StoreKey} storeKey
24
+ * @param {boolean} [removeAll=false] Whether to remove all callbacks for a hookName,
25
+ * without regard to namespace. Used to create
26
+ * `removeAll*` functions.
27
+ *
28
+ * @return {RemoveHook} Function that removes hooks.
29
+ */
30
+
31
+ function createRemoveHook(hooks, storeKey, removeAll = false) {
32
+ return function removeHook(hookName, namespace) {
33
+ const hooksStore = hooks[storeKey];
34
+
35
+ if (!validateHookName(hookName)) {
36
+ return;
37
+ }
38
+
39
+ if (!removeAll && !validateNamespace(namespace)) {
40
+ return;
41
+ } // Bail if no hooks exist by this name
42
+
43
+
44
+ if (!hooksStore[hookName]) {
45
+ return 0;
46
+ }
47
+
48
+ let handlersRemoved = 0;
49
+
50
+ if (removeAll) {
51
+ handlersRemoved = hooksStore[hookName].handlers.length;
52
+ hooksStore[hookName] = {
53
+ runs: hooksStore[hookName].runs,
54
+ handlers: []
55
+ };
56
+ } else {
57
+ // Try to find the specified callback to remove.
58
+ const handlers = hooksStore[hookName].handlers;
59
+
60
+ for (let i = handlers.length - 1; i >= 0; i--) {
61
+ if (handlers[i].namespace === namespace) {
62
+ handlers.splice(i, 1);
63
+ handlersRemoved++; // This callback may also be part of a hook that is
64
+ // currently executing. If the callback we're removing
65
+ // comes after the current callback, there's no problem;
66
+ // otherwise we need to decrease the execution index of any
67
+ // other runs by 1 to account for the removed element.
68
+
69
+ hooksStore.__current.forEach(hookInfo => {
70
+ if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
71
+ hookInfo.currentIndex--;
72
+ }
73
+ });
74
+ }
75
+ }
76
+ }
77
+
78
+ if (hookName !== 'hookRemoved') {
79
+ hooks.doAction('hookRemoved', hookName, namespace);
80
+ }
81
+
82
+ return handlersRemoved;
83
+ };
84
+ }
85
+
86
+ export default createRemoveHook;
87
+ //# sourceMappingURL=createRemoveHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/hooks/src/createRemoveHook.js"],"names":["validateNamespace","validateHookName","createRemoveHook","hooks","storeKey","removeAll","removeHook","hookName","namespace","hooksStore","handlersRemoved","handlers","length","runs","i","splice","__current","forEach","hookInfo","name","currentIndex","doAction"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,iBAAP,MAA8B,wBAA9B;AACA,OAAOC,gBAAP,MAA6B,uBAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,gBAAT,CAA2BC,KAA3B,EAAkCC,QAAlC,EAA4CC,SAAS,GAAG,KAAxD,EAAgE;AAC/D,SAAO,SAASC,UAAT,CAAqBC,QAArB,EAA+BC,SAA/B,EAA2C;AACjD,UAAMC,UAAU,GAAGN,KAAK,CAAEC,QAAF,CAAxB;;AAEA,QAAK,CAAEH,gBAAgB,CAAEM,QAAF,CAAvB,EAAsC;AACrC;AACA;;AAED,QAAK,CAAEF,SAAF,IAAe,CAAEL,iBAAiB,CAAEQ,SAAF,CAAvC,EAAuD;AACtD;AACA,KATgD,CAWjD;;;AACA,QAAK,CAAEC,UAAU,CAAEF,QAAF,CAAjB,EAAgC;AAC/B,aAAO,CAAP;AACA;;AAED,QAAIG,eAAe,GAAG,CAAtB;;AAEA,QAAKL,SAAL,EAAiB;AAChBK,MAAAA,eAAe,GAAGD,UAAU,CAAEF,QAAF,CAAV,CAAuBI,QAAvB,CAAgCC,MAAlD;AACAH,MAAAA,UAAU,CAAEF,QAAF,CAAV,GAAyB;AACxBM,QAAAA,IAAI,EAAEJ,UAAU,CAAEF,QAAF,CAAV,CAAuBM,IADL;AAExBF,QAAAA,QAAQ,EAAE;AAFc,OAAzB;AAIA,KAND,MAMO;AACN;AACA,YAAMA,QAAQ,GAAGF,UAAU,CAAEF,QAAF,CAAV,CAAuBI,QAAxC;;AACA,WAAM,IAAIG,CAAC,GAAGH,QAAQ,CAACC,MAAT,GAAkB,CAAhC,EAAmCE,CAAC,IAAI,CAAxC,EAA2CA,CAAC,EAA5C,EAAiD;AAChD,YAAKH,QAAQ,CAAEG,CAAF,CAAR,CAAcN,SAAd,KAA4BA,SAAjC,EAA6C;AAC5CG,UAAAA,QAAQ,CAACI,MAAT,CAAiBD,CAAjB,EAAoB,CAApB;AACAJ,UAAAA,eAAe,GAF6B,CAG5C;AACA;AACA;AACA;AACA;;AACAD,UAAAA,UAAU,CAACO,SAAX,CAAqBC,OAArB,CAAgCC,QAAF,IAAgB;AAC7C,gBACCA,QAAQ,CAACC,IAAT,KAAkBZ,QAAlB,IACAW,QAAQ,CAACE,YAAT,IAAyBN,CAF1B,EAGE;AACDI,cAAAA,QAAQ,CAACE,YAAT;AACA;AACD,WAPD;AAQA;AACD;AACD;;AAED,QAAKb,QAAQ,KAAK,aAAlB,EAAkC;AACjCJ,MAAAA,KAAK,CAACkB,QAAN,CAAgB,aAAhB,EAA+Bd,QAA/B,EAAyCC,SAAzC;AACA;;AAED,WAAOE,eAAP;AACA,GArDD;AAsDA;;AAED,eAAeR,gBAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport validateNamespace from './validateNamespace.js';\nimport validateHookName from './validateHookName.js';\n\n/**\n * @callback RemoveHook\n * Removes the specified callback (or all callbacks) from the hook with a given hookName\n * and namespace.\n *\n * @param {string} hookName The name of the hook to modify.\n * @param {string} namespace The unique namespace identifying the callback in the\n * form `vendor/plugin/function`.\n *\n * @return {number | undefined} The number of callbacks removed.\n */\n\n/**\n * Returns a function which, when invoked, will remove a specified hook or all\n * hooks by the given name.\n *\n * @param {import('.').Hooks} hooks Hooks instance.\n * @param {import('.').StoreKey} storeKey\n * @param {boolean} [removeAll=false] Whether to remove all callbacks for a hookName,\n * without regard to namespace. Used to create\n * `removeAll*` functions.\n *\n * @return {RemoveHook} Function that removes hooks.\n */\nfunction createRemoveHook( hooks, storeKey, removeAll = false ) {\n\treturn function removeHook( hookName, namespace ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\tif ( ! validateHookName( hookName ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! removeAll && ! validateNamespace( namespace ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Bail if no hooks exist by this name\n\t\tif ( ! hooksStore[ hookName ] ) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tlet handlersRemoved = 0;\n\n\t\tif ( removeAll ) {\n\t\t\thandlersRemoved = hooksStore[ hookName ].handlers.length;\n\t\t\thooksStore[ hookName ] = {\n\t\t\t\truns: hooksStore[ hookName ].runs,\n\t\t\t\thandlers: [],\n\t\t\t};\n\t\t} else {\n\t\t\t// Try to find the specified callback to remove.\n\t\t\tconst handlers = hooksStore[ hookName ].handlers;\n\t\t\tfor ( let i = handlers.length - 1; i >= 0; i-- ) {\n\t\t\t\tif ( handlers[ i ].namespace === namespace ) {\n\t\t\t\t\thandlers.splice( i, 1 );\n\t\t\t\t\thandlersRemoved++;\n\t\t\t\t\t// This callback may also be part of a hook that is\n\t\t\t\t\t// currently executing. If the callback we're removing\n\t\t\t\t\t// comes after the current callback, there's no problem;\n\t\t\t\t\t// otherwise we need to decrease the execution index of any\n\t\t\t\t\t// other runs by 1 to account for the removed element.\n\t\t\t\t\thooksStore.__current.forEach( ( hookInfo ) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\thookInfo.name === hookName &&\n\t\t\t\t\t\t\thookInfo.currentIndex >= i\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\thookInfo.currentIndex--;\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif ( hookName !== 'hookRemoved' ) {\n\t\t\thooks.doAction( 'hookRemoved', hookName, namespace );\n\t\t}\n\n\t\treturn handlersRemoved;\n\t};\n}\n\nexport default createRemoveHook;\n"]}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Returns a function which, when invoked, will execute all callbacks
3
+ * registered to a hook of the specified type, optionally returning the final
4
+ * value of the call chain.
5
+ *
6
+ * @param {import('.').Hooks} hooks Hooks instance.
7
+ * @param {import('.').StoreKey} storeKey
8
+ * @param {boolean} [returnFirstArg=false] Whether each hook callback is expected to
9
+ * return its first argument.
10
+ *
11
+ * @return {(hookName:string, ...args: unknown[]) => unknown} Function that runs hook callbacks.
12
+ */
13
+ function createRunHook(hooks, storeKey, returnFirstArg = false) {
14
+ return function runHooks(hookName, ...args) {
15
+ const hooksStore = hooks[storeKey];
16
+
17
+ if (!hooksStore[hookName]) {
18
+ hooksStore[hookName] = {
19
+ handlers: [],
20
+ runs: 0
21
+ };
22
+ }
23
+
24
+ hooksStore[hookName].runs++;
25
+ const handlers = hooksStore[hookName].handlers; // The following code is stripped from production builds.
26
+
27
+ if ('production' !== process.env.NODE_ENV) {
28
+ // Handle any 'all' hooks registered.
29
+ if ('hookAdded' !== hookName && hooksStore.all) {
30
+ handlers.push(...hooksStore.all.handlers);
31
+ }
32
+ }
33
+
34
+ if (!handlers || !handlers.length) {
35
+ return returnFirstArg ? args[0] : undefined;
36
+ }
37
+
38
+ const hookInfo = {
39
+ name: hookName,
40
+ currentIndex: 0
41
+ };
42
+
43
+ hooksStore.__current.push(hookInfo);
44
+
45
+ while (hookInfo.currentIndex < handlers.length) {
46
+ const handler = handlers[hookInfo.currentIndex];
47
+ const result = handler.callback.apply(null, args);
48
+
49
+ if (returnFirstArg) {
50
+ args[0] = result;
51
+ }
52
+
53
+ hookInfo.currentIndex++;
54
+ }
55
+
56
+ hooksStore.__current.pop();
57
+
58
+ if (returnFirstArg) {
59
+ return args[0];
60
+ }
61
+ };
62
+ }
63
+
64
+ export default createRunHook;
65
+ //# sourceMappingURL=createRunHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/hooks/src/createRunHook.js"],"names":["createRunHook","hooks","storeKey","returnFirstArg","runHooks","hookName","args","hooksStore","handlers","runs","process","env","NODE_ENV","all","push","length","undefined","hookInfo","name","currentIndex","__current","handler","result","callback","apply","pop"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAT,CAAwBC,KAAxB,EAA+BC,QAA/B,EAAyCC,cAAc,GAAG,KAA1D,EAAkE;AACjE,SAAO,SAASC,QAAT,CAAmBC,QAAnB,EAA6B,GAAGC,IAAhC,EAAuC;AAC7C,UAAMC,UAAU,GAAGN,KAAK,CAAEC,QAAF,CAAxB;;AAEA,QAAK,CAAEK,UAAU,CAAEF,QAAF,CAAjB,EAAgC;AAC/BE,MAAAA,UAAU,CAAEF,QAAF,CAAV,GAAyB;AACxBG,QAAAA,QAAQ,EAAE,EADc;AAExBC,QAAAA,IAAI,EAAE;AAFkB,OAAzB;AAIA;;AAEDF,IAAAA,UAAU,CAAEF,QAAF,CAAV,CAAuBI,IAAvB;AAEA,UAAMD,QAAQ,GAAGD,UAAU,CAAEF,QAAF,CAAV,CAAuBG,QAAxC,CAZ6C,CAc7C;;AACA,QAAK,iBAAiBE,OAAO,CAACC,GAAR,CAAYC,QAAlC,EAA6C;AAC5C;AACA,UAAK,gBAAgBP,QAAhB,IAA4BE,UAAU,CAACM,GAA5C,EAAkD;AACjDL,QAAAA,QAAQ,CAACM,IAAT,CAAe,GAAGP,UAAU,CAACM,GAAX,CAAeL,QAAjC;AACA;AACD;;AAED,QAAK,CAAEA,QAAF,IAAc,CAAEA,QAAQ,CAACO,MAA9B,EAAuC;AACtC,aAAOZ,cAAc,GAAGG,IAAI,CAAE,CAAF,CAAP,GAAeU,SAApC;AACA;;AAED,UAAMC,QAAQ,GAAG;AAChBC,MAAAA,IAAI,EAAEb,QADU;AAEhBc,MAAAA,YAAY,EAAE;AAFE,KAAjB;;AAKAZ,IAAAA,UAAU,CAACa,SAAX,CAAqBN,IAArB,CAA2BG,QAA3B;;AAEA,WAAQA,QAAQ,CAACE,YAAT,GAAwBX,QAAQ,CAACO,MAAzC,EAAkD;AACjD,YAAMM,OAAO,GAAGb,QAAQ,CAAES,QAAQ,CAACE,YAAX,CAAxB;AAEA,YAAMG,MAAM,GAAGD,OAAO,CAACE,QAAR,CAAiBC,KAAjB,CAAwB,IAAxB,EAA8BlB,IAA9B,CAAf;;AACA,UAAKH,cAAL,EAAsB;AACrBG,QAAAA,IAAI,CAAE,CAAF,CAAJ,GAAYgB,MAAZ;AACA;;AAEDL,MAAAA,QAAQ,CAACE,YAAT;AACA;;AAEDZ,IAAAA,UAAU,CAACa,SAAX,CAAqBK,GAArB;;AAEA,QAAKtB,cAAL,EAAsB;AACrB,aAAOG,IAAI,CAAE,CAAF,CAAX;AACA;AACD,GAjDD;AAkDA;;AAED,eAAeN,aAAf","sourcesContent":["/**\n * Returns a function which, when invoked, will execute all callbacks\n * registered to a hook of the specified type, optionally returning the final\n * value of the call chain.\n *\n * @param {import('.').Hooks} hooks Hooks instance.\n * @param {import('.').StoreKey} storeKey\n * @param {boolean} [returnFirstArg=false] Whether each hook callback is expected to\n * return its first argument.\n *\n * @return {(hookName:string, ...args: unknown[]) => unknown} Function that runs hook callbacks.\n */\nfunction createRunHook( hooks, storeKey, returnFirstArg = false ) {\n\treturn function runHooks( hookName, ...args ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\tif ( ! hooksStore[ hookName ] ) {\n\t\t\thooksStore[ hookName ] = {\n\t\t\t\thandlers: [],\n\t\t\t\truns: 0,\n\t\t\t};\n\t\t}\n\n\t\thooksStore[ hookName ].runs++;\n\n\t\tconst handlers = hooksStore[ hookName ].handlers;\n\n\t\t// The following code is stripped from production builds.\n\t\tif ( 'production' !== process.env.NODE_ENV ) {\n\t\t\t// Handle any 'all' hooks registered.\n\t\t\tif ( 'hookAdded' !== hookName && hooksStore.all ) {\n\t\t\t\thandlers.push( ...hooksStore.all.handlers );\n\t\t\t}\n\t\t}\n\n\t\tif ( ! handlers || ! handlers.length ) {\n\t\t\treturn returnFirstArg ? args[ 0 ] : undefined;\n\t\t}\n\n\t\tconst hookInfo = {\n\t\t\tname: hookName,\n\t\t\tcurrentIndex: 0,\n\t\t};\n\n\t\thooksStore.__current.push( hookInfo );\n\n\t\twhile ( hookInfo.currentIndex < handlers.length ) {\n\t\t\tconst handler = handlers[ hookInfo.currentIndex ];\n\n\t\t\tconst result = handler.callback.apply( null, args );\n\t\t\tif ( returnFirstArg ) {\n\t\t\t\targs[ 0 ] = result;\n\t\t\t}\n\n\t\t\thookInfo.currentIndex++;\n\t\t}\n\n\t\thooksStore.__current.pop();\n\n\t\tif ( returnFirstArg ) {\n\t\t\treturn args[ 0 ];\n\t\t}\n\t};\n}\n\nexport default createRunHook;\n"]}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import createHooks from './createHooks';
5
+ /** @typedef {(...args: any[])=>any} Callback */
6
+
7
+ /**
8
+ * @typedef Handler
9
+ * @property {Callback} callback The callback
10
+ * @property {string} namespace The namespace
11
+ * @property {number} priority The namespace
12
+ */
13
+
14
+ /**
15
+ * @typedef Hook
16
+ * @property {Handler[]} handlers Array of handlers
17
+ * @property {number} runs Run counter
18
+ */
19
+
20
+ /**
21
+ * @typedef Current
22
+ * @property {string} name Hook name
23
+ * @property {number} currentIndex The index
24
+ */
25
+
26
+ /**
27
+ * @typedef {Record<string, Hook> & {__current: Current[]}} Store
28
+ */
29
+
30
+ /**
31
+ * @typedef {'actions' | 'filters'} StoreKey
32
+ */
33
+
34
+ /**
35
+ * @typedef {import('./createHooks').Hooks} Hooks
36
+ */
37
+
38
+ export const defaultHooks = createHooks();
39
+ const {
40
+ addAction,
41
+ addFilter,
42
+ removeAction,
43
+ removeFilter,
44
+ hasAction,
45
+ hasFilter,
46
+ removeAllActions,
47
+ removeAllFilters,
48
+ doAction,
49
+ applyFilters,
50
+ currentAction,
51
+ currentFilter,
52
+ doingAction,
53
+ doingFilter,
54
+ didAction,
55
+ didFilter,
56
+ actions,
57
+ filters
58
+ } = defaultHooks;
59
+ export { createHooks, addAction, addFilter, removeAction, removeFilter, hasAction, hasFilter, removeAllActions, removeAllFilters, doAction, applyFilters, currentAction, currentFilter, doingAction, doingFilter, didAction, didFilter, actions, filters };
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/hooks/src/index.js"],"names":["createHooks","defaultHooks","addAction","addFilter","removeAction","removeFilter","hasAction","hasFilter","removeAllActions","removeAllFilters","doAction","applyFilters","currentAction","currentFilter","doingAction","doingFilter","didAction","didFilter","actions","filters"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAP,MAAwB,eAAxB;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,OAAO,MAAMC,YAAY,GAAGD,WAAW,EAAhC;AAEP,MAAM;AACLE,EAAAA,SADK;AAELC,EAAAA,SAFK;AAGLC,EAAAA,YAHK;AAILC,EAAAA,YAJK;AAKLC,EAAAA,SALK;AAMLC,EAAAA,SANK;AAOLC,EAAAA,gBAPK;AAQLC,EAAAA,gBARK;AASLC,EAAAA,QATK;AAULC,EAAAA,YAVK;AAWLC,EAAAA,aAXK;AAYLC,EAAAA,aAZK;AAaLC,EAAAA,WAbK;AAcLC,EAAAA,WAdK;AAeLC,EAAAA,SAfK;AAgBLC,EAAAA,SAhBK;AAiBLC,EAAAA,OAjBK;AAkBLC,EAAAA;AAlBK,IAmBFlB,YAnBJ;AAqBA,SACCD,WADD,EAECE,SAFD,EAGCC,SAHD,EAICC,YAJD,EAKCC,YALD,EAMCC,SAND,EAOCC,SAPD,EAQCC,gBARD,EASCC,gBATD,EAUCC,QAVD,EAWCC,YAXD,EAYCC,aAZD,EAaCC,aAbD,EAcCC,WAdD,EAeCC,WAfD,EAgBCC,SAhBD,EAiBCC,SAjBD,EAkBCC,OAlBD,EAmBCC,OAnBD","sourcesContent":["/**\n * Internal dependencies\n */\nimport createHooks from './createHooks';\n\n/** @typedef {(...args: any[])=>any} Callback */\n\n/**\n * @typedef Handler\n * @property {Callback} callback The callback\n * @property {string} namespace The namespace\n * @property {number} priority The namespace\n */\n\n/**\n * @typedef Hook\n * @property {Handler[]} handlers Array of handlers\n * @property {number} runs Run counter\n */\n\n/**\n * @typedef Current\n * @property {string} name Hook name\n * @property {number} currentIndex The index\n */\n\n/**\n * @typedef {Record<string, Hook> & {__current: Current[]}} Store\n */\n\n/**\n * @typedef {'actions' | 'filters'} StoreKey\n */\n\n/**\n * @typedef {import('./createHooks').Hooks} Hooks\n */\n\nexport const defaultHooks = createHooks();\n\nconst {\n\taddAction,\n\taddFilter,\n\tremoveAction,\n\tremoveFilter,\n\thasAction,\n\thasFilter,\n\tremoveAllActions,\n\tremoveAllFilters,\n\tdoAction,\n\tapplyFilters,\n\tcurrentAction,\n\tcurrentFilter,\n\tdoingAction,\n\tdoingFilter,\n\tdidAction,\n\tdidFilter,\n\tactions,\n\tfilters,\n} = defaultHooks;\n\nexport {\n\tcreateHooks,\n\taddAction,\n\taddFilter,\n\tremoveAction,\n\tremoveFilter,\n\thasAction,\n\thasFilter,\n\tremoveAllActions,\n\tremoveAllFilters,\n\tdoAction,\n\tapplyFilters,\n\tcurrentAction,\n\tcurrentFilter,\n\tdoingAction,\n\tdoingFilter,\n\tdidAction,\n\tdidFilter,\n\tactions,\n\tfilters,\n};\n"]}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Validate a hookName string.
3
+ *
4
+ * @param {string} hookName The hook name to validate. Should be a non empty string containing
5
+ * only numbers, letters, dashes, periods and underscores. Also,
6
+ * the hook name cannot begin with `__`.
7
+ *
8
+ * @return {boolean} Whether the hook name is valid.
9
+ */
10
+ function validateHookName(hookName) {
11
+ if ('string' !== typeof hookName || '' === hookName) {
12
+ // eslint-disable-next-line no-console
13
+ console.error('The hook name must be a non-empty string.');
14
+ return false;
15
+ }
16
+
17
+ if (/^__/.test(hookName)) {
18
+ // eslint-disable-next-line no-console
19
+ console.error('The hook name cannot begin with `__`.');
20
+ return false;
21
+ }
22
+
23
+ if (!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(hookName)) {
24
+ // eslint-disable-next-line no-console
25
+ console.error('The hook name can only contain numbers, letters, dashes, periods and underscores.');
26
+ return false;
27
+ }
28
+
29
+ return true;
30
+ }
31
+
32
+ export default validateHookName;
33
+ //# sourceMappingURL=validateHookName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/hooks/src/validateHookName.js"],"names":["validateHookName","hookName","console","error","test"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,gBAAT,CAA2BC,QAA3B,EAAsC;AACrC,MAAK,aAAa,OAAOA,QAApB,IAAgC,OAAOA,QAA5C,EAAuD;AACtD;AACAC,IAAAA,OAAO,CAACC,KAAR,CAAe,2CAAf;AACA,WAAO,KAAP;AACA;;AAED,MAAK,MAAMC,IAAN,CAAYH,QAAZ,CAAL,EAA8B;AAC7B;AACAC,IAAAA,OAAO,CAACC,KAAR,CAAe,uCAAf;AACA,WAAO,KAAP;AACA;;AAED,MAAK,CAAE,4BAA4BC,IAA5B,CAAkCH,QAAlC,CAAP,EAAsD;AACrD;AACAC,IAAAA,OAAO,CAACC,KAAR,CACC,mFADD;AAGA,WAAO,KAAP;AACA;;AAED,SAAO,IAAP;AACA;;AAED,eAAeH,gBAAf","sourcesContent":["/**\n * Validate a hookName string.\n *\n * @param {string} hookName The hook name to validate. Should be a non empty string containing\n * only numbers, letters, dashes, periods and underscores. Also,\n * the hook name cannot begin with `__`.\n *\n * @return {boolean} Whether the hook name is valid.\n */\nfunction validateHookName( hookName ) {\n\tif ( 'string' !== typeof hookName || '' === hookName ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error( 'The hook name must be a non-empty string.' );\n\t\treturn false;\n\t}\n\n\tif ( /^__/.test( hookName ) ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error( 'The hook name cannot begin with `__`.' );\n\t\treturn false;\n\t}\n\n\tif ( ! /^[a-zA-Z][a-zA-Z0-9_.-]*$/.test( hookName ) ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error(\n\t\t\t'The hook name can only contain numbers, letters, dashes, periods and underscores.'\n\t\t);\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nexport default validateHookName;\n"]}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Validate a namespace string.
3
+ *
4
+ * @param {string} namespace The namespace to validate - should take the form
5
+ * `vendor/plugin/function`.
6
+ *
7
+ * @return {boolean} Whether the namespace is valid.
8
+ */
9
+ function validateNamespace(namespace) {
10
+ if ('string' !== typeof namespace || '' === namespace) {
11
+ // eslint-disable-next-line no-console
12
+ console.error('The namespace must be a non-empty string.');
13
+ return false;
14
+ }
15
+
16
+ if (!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(namespace)) {
17
+ // eslint-disable-next-line no-console
18
+ console.error('The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.');
19
+ return false;
20
+ }
21
+
22
+ return true;
23
+ }
24
+
25
+ export default validateNamespace;
26
+ //# sourceMappingURL=validateNamespace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/hooks/src/validateNamespace.js"],"names":["validateNamespace","namespace","console","error","test"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,iBAAT,CAA4BC,SAA5B,EAAwC;AACvC,MAAK,aAAa,OAAOA,SAApB,IAAiC,OAAOA,SAA7C,EAAyD;AACxD;AACAC,IAAAA,OAAO,CAACC,KAAR,CAAe,2CAAf;AACA,WAAO,KAAP;AACA;;AAED,MAAK,CAAE,+BAA+BC,IAA/B,CAAqCH,SAArC,CAAP,EAA0D;AACzD;AACAC,IAAAA,OAAO,CAACC,KAAR,CACC,4FADD;AAGA,WAAO,KAAP;AACA;;AAED,SAAO,IAAP;AACA;;AAED,eAAeH,iBAAf","sourcesContent":["/**\n * Validate a namespace string.\n *\n * @param {string} namespace The namespace to validate - should take the form\n * `vendor/plugin/function`.\n *\n * @return {boolean} Whether the namespace is valid.\n */\nfunction validateNamespace( namespace ) {\n\tif ( 'string' !== typeof namespace || '' === namespace ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error( 'The namespace must be a non-empty string.' );\n\t\treturn false;\n\t}\n\n\tif ( ! /^[a-zA-Z][a-zA-Z0-9_.\\-\\/]*$/.test( namespace ) ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error(\n\t\t\t'The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.'\n\t\t);\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nexport default validateNamespace;\n"]}
@@ -0,0 +1,25 @@
1
+ export default createAddHook;
2
+ /**
3
+ * Adds the hook to the appropriate hooks container.
4
+ */
5
+ export type AddHook = (hookName: string, namespace: string, callback: import('.').Callback, priority?: number | undefined) => any;
6
+ /**
7
+ * @callback AddHook
8
+ *
9
+ * Adds the hook to the appropriate hooks container.
10
+ *
11
+ * @param {string} hookName Name of hook to add
12
+ * @param {string} namespace The unique namespace identifying the callback in the form `vendor/plugin/function`.
13
+ * @param {import('.').Callback} callback Function to call when the hook is run
14
+ * @param {number} [priority=10] Priority of this hook
15
+ */
16
+ /**
17
+ * Returns a function which, when invoked, will add a hook.
18
+ *
19
+ * @param {import('.').Hooks} hooks Hooks instance.
20
+ * @param {import('.').StoreKey} storeKey
21
+ *
22
+ * @return {AddHook} Function that adds a new hook.
23
+ */
24
+ declare function createAddHook(hooks: import('.').Hooks, storeKey: import('.').StoreKey): AddHook;
25
+ //# sourceMappingURL=createAddHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAddHook.d.ts","sourceRoot":"","sources":["../src/createAddHook.js"],"names":[],"mappings":";;;;iCAWW,MAAM,aACN,MAAM,YACN,OAAO,GAAG,EAAE,QAAQ;AAP/B;;;;;;;;;GASG;AAEH;;;;;;;GAOG;AACH,sCALW,OAAO,GAAG,EAAE,KAAK,YACjB,OAAO,GAAG,EAAE,QAAQ,GAEnB,OAAO,CAiFlB"}
@@ -0,0 +1,13 @@
1
+ export default createCurrentHook;
2
+ /**
3
+ * Returns a function which, when invoked, will return the name of the
4
+ * currently running hook, or `null` if no hook of the given type is currently
5
+ * running.
6
+ *
7
+ * @param {import('.').Hooks} hooks Hooks instance.
8
+ * @param {import('.').StoreKey} storeKey
9
+ *
10
+ * @return {() => string | null} Function that returns the current hook name or null.
11
+ */
12
+ declare function createCurrentHook(hooks: import('.').Hooks, storeKey: import('.').StoreKey): () => string | null;
13
+ //# sourceMappingURL=createCurrentHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCurrentHook.d.ts","sourceRoot":"","sources":["../src/createCurrentHook.js"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;AACH,0CALW,OAAO,GAAG,EAAE,KAAK,YACjB,OAAO,GAAG,EAAE,QAAQ,GAEnB,MAAM,MAAM,GAAG,IAAI,CAW9B"}
@@ -0,0 +1,25 @@
1
+ export default createDidHook;
2
+ /**
3
+ * Returns the number of times an action has been fired.
4
+ */
5
+ export type DidHook = (hookName: string) => number | undefined;
6
+ /**
7
+ * @callback DidHook
8
+ *
9
+ * Returns the number of times an action has been fired.
10
+ *
11
+ * @param {string} hookName The hook name to check.
12
+ *
13
+ * @return {number | undefined} The number of times the hook has run.
14
+ */
15
+ /**
16
+ * Returns a function which, when invoked, will return the number of times a
17
+ * hook has been called.
18
+ *
19
+ * @param {import('.').Hooks} hooks Hooks instance.
20
+ * @param {import('.').StoreKey} storeKey
21
+ *
22
+ * @return {DidHook} Function that returns a hook's call count.
23
+ */
24
+ declare function createDidHook(hooks: import('.').Hooks, storeKey: import('.').StoreKey): DidHook;
25
+ //# sourceMappingURL=createDidHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDidHook.d.ts","sourceRoot":"","sources":["../src/createDidHook.js"],"names":[],"mappings":";;;;iCAUW,MAAM,KAEL,MAAM,GAAG,SAAS;AAP9B;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,sCALW,OAAO,GAAG,EAAE,KAAK,YACjB,OAAO,GAAG,EAAE,QAAQ,GAEnB,OAAO,CAclB"}
@@ -0,0 +1,26 @@
1
+ export default createDoingHook;
2
+ /**
3
+ * Returns whether a hook is currently being executed.
4
+ */
5
+ export type DoingHook = (hookName?: string | undefined) => boolean;
6
+ /**
7
+ * @callback DoingHook
8
+ * Returns whether a hook is currently being executed.
9
+ *
10
+ * @param {string} [hookName] The name of the hook to check for. If
11
+ * omitted, will check for any hook being executed.
12
+ *
13
+ * @return {boolean} Whether the hook is being executed.
14
+ */
15
+ /**
16
+ * Returns a function which, when invoked, will return whether a hook is
17
+ * currently being executed.
18
+ *
19
+ * @param {import('.').Hooks} hooks Hooks instance.
20
+ * @param {import('.').StoreKey} storeKey
21
+ *
22
+ * @return {DoingHook} Function that returns whether a hook is currently
23
+ * being executed.
24
+ */
25
+ declare function createDoingHook(hooks: import('.').Hooks, storeKey: import('.').StoreKey): DoingHook;
26
+ //# sourceMappingURL=createDoingHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDoingHook.d.ts","sourceRoot":"","sources":["../src/createDoingHook.js"],"names":[],"mappings":";;;;2DAOY,OAAO;AAPnB;;;;;;;;GAQG;AAEH;;;;;;;;;GASG;AACH,wCANW,OAAO,GAAG,EAAE,KAAK,YACjB,OAAO,GAAG,EAAE,QAAQ,GAEnB,SAAS,CAiBpB"}
@@ -0,0 +1,28 @@
1
+ export default createHasHook;
2
+ /**
3
+ * Returns whether any handlers are attached for the given hookName and optional namespace.
4
+ */
5
+ export type HasHook = (hookName: string, namespace?: string | undefined) => boolean;
6
+ /**
7
+ * @callback HasHook
8
+ *
9
+ * Returns whether any handlers are attached for the given hookName and optional namespace.
10
+ *
11
+ * @param {string} hookName The name of the hook to check for.
12
+ * @param {string} [namespace] Optional. The unique namespace identifying the callback
13
+ * in the form `vendor/plugin/function`.
14
+ *
15
+ * @return {boolean} Whether there are handlers that are attached to the given hook.
16
+ */
17
+ /**
18
+ * Returns a function which, when invoked, will return whether any handlers are
19
+ * attached to a particular hook.
20
+ *
21
+ * @param {import('.').Hooks} hooks Hooks instance.
22
+ * @param {import('.').StoreKey} storeKey
23
+ *
24
+ * @return {HasHook} Function that returns whether any handlers are
25
+ * attached to a particular hook and optional namespace.
26
+ */
27
+ declare function createHasHook(hooks: import('.').Hooks, storeKey: import('.').StoreKey): HasHook;
28
+ //# sourceMappingURL=createHasHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHasHook.d.ts","sourceRoot":"","sources":["../src/createHasHook.js"],"names":[],"mappings":";;;;iCAKW,MAAM,qCAIL,OAAO;AATnB;;;;;;;;;;GAUG;AACH;;;;;;;;;GASG;AACH,sCANW,OAAO,GAAG,EAAE,KAAK,YACjB,OAAO,GAAG,EAAE,QAAQ,GAEnB,OAAO,CAmBlB"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Internal class for constructing hooks. Use `createHooks()` function
3
+ *
4
+ * Note, it is necessary to expose this class to make its type public.
5
+ *
6
+ * @private
7
+ */
8
+ export class _Hooks {
9
+ /** @type {import('.').Store} actions */
10
+ actions: import('.').Store;
11
+ /** @type {import('.').Store} filters */
12
+ filters: import('.').Store;
13
+ addAction: import("./createAddHook").AddHook;
14
+ addFilter: import("./createAddHook").AddHook;
15
+ removeAction: import("./createRemoveHook").RemoveHook;
16
+ removeFilter: import("./createRemoveHook").RemoveHook;
17
+ hasAction: import("./createHasHook").HasHook;
18
+ hasFilter: import("./createHasHook").HasHook;
19
+ removeAllActions: import("./createRemoveHook").RemoveHook;
20
+ removeAllFilters: import("./createRemoveHook").RemoveHook;
21
+ doAction: (hookName: string, ...args: unknown[]) => unknown;
22
+ applyFilters: (hookName: string, ...args: unknown[]) => unknown;
23
+ currentAction: () => string | null;
24
+ currentFilter: () => string | null;
25
+ doingAction: import("./createDoingHook").DoingHook;
26
+ doingFilter: import("./createDoingHook").DoingHook;
27
+ didAction: import("./createDidHook").DidHook;
28
+ didFilter: import("./createDidHook").DidHook;
29
+ }
30
+ export default createHooks;
31
+ export type Hooks = _Hooks;
32
+ /** @typedef {_Hooks} Hooks */
33
+ /**
34
+ * Returns an instance of the hooks object.
35
+ *
36
+ * @return {Hooks} A Hooks instance.
37
+ */
38
+ declare function createHooks(): Hooks;
39
+ //# sourceMappingURL=createHooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHooks.d.ts","sourceRoot":"","sources":["../src/createHooks.js"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH;IAEE,wCAAwC;IACxC,SADW,OAAO,GAAG,EAAE,KAAK,CACQ;IAGpC,wCAAwC;IACxC,SADW,OAAO,GAAG,EAAE,KAAK,CACQ;IAGpC,6CAAiD;IACjD,6CAAiD;IACjD,sDAAuD;IACvD,sDAAuD;IACvD,6CAAiD;IACjD,6CAAiD;IACjD,0DAAiE;IACjE,0DAAiE;IACjE,4DAAgD;IAChD,gEAA0D;IAC1D,mCAAyD;IACzD,mCAAyD;IACzD,mDAAqD;IACrD,mDAAqD;IACrD,6CAAiD;IACjD,6CAAiD;CAElD;;oBAEa,MAAM;AAApB,8BAA8B;AAE9B;;;;GAIG;AACH,gCAFY,KAAK,CAIhB"}
@@ -0,0 +1,31 @@
1
+ export default createRemoveHook;
2
+ /**
3
+ * Removes the specified callback (or all callbacks) from the hook with a given hookName
4
+ * and namespace.
5
+ */
6
+ export type RemoveHook = (hookName: string, namespace: string) => number | undefined;
7
+ /**
8
+ * @callback RemoveHook
9
+ * Removes the specified callback (or all callbacks) from the hook with a given hookName
10
+ * and namespace.
11
+ *
12
+ * @param {string} hookName The name of the hook to modify.
13
+ * @param {string} namespace The unique namespace identifying the callback in the
14
+ * form `vendor/plugin/function`.
15
+ *
16
+ * @return {number | undefined} The number of callbacks removed.
17
+ */
18
+ /**
19
+ * Returns a function which, when invoked, will remove a specified hook or all
20
+ * hooks by the given name.
21
+ *
22
+ * @param {import('.').Hooks} hooks Hooks instance.
23
+ * @param {import('.').StoreKey} storeKey
24
+ * @param {boolean} [removeAll=false] Whether to remove all callbacks for a hookName,
25
+ * without regard to namespace. Used to create
26
+ * `removeAll*` functions.
27
+ *
28
+ * @return {RemoveHook} Function that removes hooks.
29
+ */
30
+ declare function createRemoveHook(hooks: import('.').Hooks, storeKey: import('.').StoreKey, removeAll?: boolean | undefined): RemoveHook;
31
+ //# sourceMappingURL=createRemoveHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRemoveHook.d.ts","sourceRoot":"","sources":["../src/createRemoveHook.js"],"names":[],"mappings":";;;;;oCAWW,MAAM,aACN,MAAM,KAGL,MAAM,GAAG,SAAS;AAT9B;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;GAWG;AACH,yCARW,OAAO,GAAG,EAAE,KAAK,YACjB,OAAO,GAAG,EAAE,QAAQ,oCAKnB,UAAU,CAyDrB"}
@@ -0,0 +1,15 @@
1
+ export default createRunHook;
2
+ /**
3
+ * Returns a function which, when invoked, will execute all callbacks
4
+ * registered to a hook of the specified type, optionally returning the final
5
+ * value of the call chain.
6
+ *
7
+ * @param {import('.').Hooks} hooks Hooks instance.
8
+ * @param {import('.').StoreKey} storeKey
9
+ * @param {boolean} [returnFirstArg=false] Whether each hook callback is expected to
10
+ * return its first argument.
11
+ *
12
+ * @return {(hookName:string, ...args: unknown[]) => unknown} Function that runs hook callbacks.
13
+ */
14
+ declare function createRunHook(hooks: import('.').Hooks, storeKey: import('.').StoreKey, returnFirstArg?: boolean | undefined): (hookName: string, ...args: unknown[]) => unknown;
15
+ //# sourceMappingURL=createRunHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRunHook.d.ts","sourceRoot":"","sources":["../src/createRunHook.js"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;AACH,sCAPW,OAAO,GAAG,EAAE,KAAK,YACjB,OAAO,GAAG,EAAE,QAAQ,oDAIT,MAAM,WAAW,OAAO,EAAE,KAAK,OAAO,CAqD3D"}
@@ -0,0 +1,88 @@
1
+ /** @typedef {(...args: any[])=>any} Callback */
2
+ /**
3
+ * @typedef Handler
4
+ * @property {Callback} callback The callback
5
+ * @property {string} namespace The namespace
6
+ * @property {number} priority The namespace
7
+ */
8
+ /**
9
+ * @typedef Hook
10
+ * @property {Handler[]} handlers Array of handlers
11
+ * @property {number} runs Run counter
12
+ */
13
+ /**
14
+ * @typedef Current
15
+ * @property {string} name Hook name
16
+ * @property {number} currentIndex The index
17
+ */
18
+ /**
19
+ * @typedef {Record<string, Hook> & {__current: Current[]}} Store
20
+ */
21
+ /**
22
+ * @typedef {'actions' | 'filters'} StoreKey
23
+ */
24
+ /**
25
+ * @typedef {import('./createHooks').Hooks} Hooks
26
+ */
27
+ export const defaultHooks: import("./createHooks")._Hooks;
28
+ export type Callback = (...args: any[]) => any;
29
+ export type Handler = {
30
+ /**
31
+ * The callback
32
+ */
33
+ callback: Callback;
34
+ /**
35
+ * The namespace
36
+ */
37
+ namespace: string;
38
+ /**
39
+ * The namespace
40
+ */
41
+ priority: number;
42
+ };
43
+ export type Hook = {
44
+ /**
45
+ * Array of handlers
46
+ */
47
+ handlers: Handler[];
48
+ /**
49
+ * Run counter
50
+ */
51
+ runs: number;
52
+ };
53
+ export type Current = {
54
+ /**
55
+ * Hook name
56
+ */
57
+ name: string;
58
+ /**
59
+ * The index
60
+ */
61
+ currentIndex: number;
62
+ };
63
+ export type Store = Record<string, Hook> & {
64
+ __current: Current[];
65
+ };
66
+ export type StoreKey = 'actions' | 'filters';
67
+ export type Hooks = import('./createHooks').Hooks;
68
+ import createHooks from "./createHooks";
69
+ export const addAction: import("./createAddHook").AddHook;
70
+ export const addFilter: import("./createAddHook").AddHook;
71
+ export const removeAction: import("./createRemoveHook").RemoveHook;
72
+ export const removeFilter: import("./createRemoveHook").RemoveHook;
73
+ export const hasAction: import("./createHasHook").HasHook;
74
+ export const hasFilter: import("./createHasHook").HasHook;
75
+ export const removeAllActions: import("./createRemoveHook").RemoveHook;
76
+ export const removeAllFilters: import("./createRemoveHook").RemoveHook;
77
+ export const doAction: (hookName: string, ...args: unknown[]) => unknown;
78
+ export const applyFilters: (hookName: string, ...args: unknown[]) => unknown;
79
+ export const currentAction: () => string | null;
80
+ export const currentFilter: () => string | null;
81
+ export const doingAction: import("./createDoingHook").DoingHook;
82
+ export const doingFilter: import("./createDoingHook").DoingHook;
83
+ export const didAction: import("./createDidHook").DidHook;
84
+ export const didFilter: import("./createDidHook").DidHook;
85
+ export const actions: Store;
86
+ export const filters: Store;
87
+ export { createHooks };
88
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAKA,gDAAgD;AAEhD;;;;;GAKG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAEH,0DAA0C;iCAjClB,GAAG,EAAE,KAAG,GAAG;;;;;cAIrB,QAAQ;;;;eACR,MAAM;;;;cACN,MAAM;;;;;;cAKN,OAAO,EAAE;;;;UACT,MAAM;;;;;;UAKN,MAAM;;;;kBACN,MAAM;;oBAIP,OAAO,MAAM,EAAE,IAAI,CAAC,GAAG;IAAC,SAAS,EAAE,OAAO,EAAE,CAAA;CAAC;uBAI7C,SAAS,GAAG,SAAS;oBAIrB,OAAO,eAAe,EAAE,KAAK"}