@wordpress/hooks 4.31.1-next.f56bd8138.0 → 4.32.1-next.47f435fc9.0
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.
- package/CHANGELOG.md +2 -0
- package/build/createAddHook.js +53 -53
- package/build/createAddHook.js.map +7 -1
- package/build/createCurrentHook.js +24 -22
- package/build/createCurrentHook.js.map +7 -1
- package/build/createDidHook.js +35 -28
- package/build/createDidHook.js.map +7 -1
- package/build/createDoingHook.js +27 -31
- package/build/createDoingHook.js.map +7 -1
- package/build/createHasHook.js +27 -29
- package/build/createHasHook.js.map +7 -1
- package/build/createHooks.js +87 -53
- package/build/createHooks.js.map +7 -1
- package/build/createRemoveHook.js +40 -43
- package/build/createRemoveHook.js.map +7 -1
- package/build/createRunHook.js +30 -32
- package/build/createRunHook.js.map +7 -1
- package/build/index.js +81 -73
- package/build/index.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build/validateHookName.js +29 -22
- package/build/validateHookName.js.map +7 -1
- package/build/validateNamespace.js +28 -19
- package/build/validateNamespace.js.map +7 -1
- package/build-module/createAddHook.js +23 -46
- package/build-module/createAddHook.js.map +7 -1
- package/build-module/createCurrentHook.js +6 -18
- package/build-module/createCurrentHook.js.map +7 -1
- package/build-module/createDidHook.js +6 -22
- package/build-module/createDidHook.js.map +7 -1
- package/build-module/createDoingHook.js +9 -27
- package/build-module/createDoingHook.js.map +7 -1
- package/build-module/createHasHook.js +9 -25
- package/build-module/createHasHook.js.map +7 -1
- package/build-module/createHooks.js +56 -47
- package/build-module/createHooks.js.map +7 -1
- package/build-module/createRemoveHook.js +10 -36
- package/build-module/createRemoveHook.js.map +7 -1
- package/build-module/createRunHook.js +12 -28
- package/build-module/createRunHook.js.map +7 -1
- package/build-module/index.js +28 -8
- package/build-module/index.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-module/validateHookName.js +11 -18
- package/build-module/validateHookName.js.map +7 -1
- package/build-module/validateNamespace.js +10 -15
- package/build-module/validateNamespace.js.map +7 -1
- package/package.json +10 -5
package/build/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport createHooks from './createHooks';\n\nexport * from './types';\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\tdoActionAsync,\n\tapplyFilters,\n\tapplyFiltersAsync,\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\tdoActionAsync,\n\tapplyFilters,\n\tapplyFiltersAsync,\n\tcurrentAction,\n\tcurrentFilter,\n\tdoingAction,\n\tdoingFilter,\n\tdidAction,\n\tdidFilter,\n\tactions,\n\tfilters,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wCAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAwB;AAExB,0BAAc,oBALd;AAOO,MAAM,mBAAe,mBAAAA,SAAY;AAExC,MAAM;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,IAAI;",
|
|
6
|
+
"names": ["createHooks"]
|
|
7
|
+
}
|
package/build/types.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
package/build/types.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nexport type { Hooks } from './createHooks';\n\nexport type Callback = ( ...args: any[] ) => any;\n\nexport type Handler = {\n\tcallback: Callback;\n\tnamespace: string;\n\tpriority: number;\n};\n\nexport type Hook = {\n\thandlers: Handler[];\n\truns: number;\n};\n\nexport type Current = {\n\tname: string;\n\tcurrentIndex: number;\n};\n\nexport type HookInfo = {\n\tname: string;\n\tcurrentIndex: number;\n};\n\nexport type Store = Record< string, Hook > & { __current: Set< Current > };\n\nexport type StoreKey = 'actions' | 'filters';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var validateHookName_exports = {};
|
|
20
|
+
__export(validateHookName_exports, {
|
|
21
|
+
default: () => validateHookName_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Validate a hookName string.
|
|
9
|
-
*
|
|
10
|
-
* @param hookName The hook name to validate. Should be a non empty string containing
|
|
11
|
-
* only numbers, letters, dashes, periods and underscores. Also,
|
|
12
|
-
* the hook name cannot begin with `__`.
|
|
13
|
-
*
|
|
14
|
-
* @return Whether the hook name is valid.
|
|
15
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(validateHookName_exports);
|
|
16
24
|
function validateHookName(hookName) {
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
console.error('The hook name must be a non-empty string.');
|
|
25
|
+
if ("string" !== typeof hookName || "" === hookName) {
|
|
26
|
+
console.error("The hook name must be a non-empty string.");
|
|
20
27
|
return false;
|
|
21
28
|
}
|
|
22
29
|
if (/^__/.test(hookName)) {
|
|
23
|
-
|
|
24
|
-
console.error('The hook name cannot begin with `__`.');
|
|
30
|
+
console.error("The hook name cannot begin with `__`.");
|
|
25
31
|
return false;
|
|
26
32
|
}
|
|
27
33
|
if (!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(hookName)) {
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
console.error(
|
|
35
|
+
"The hook name can only contain numbers, letters, dashes, periods and underscores."
|
|
36
|
+
);
|
|
30
37
|
return false;
|
|
31
38
|
}
|
|
32
39
|
return true;
|
|
33
40
|
}
|
|
34
|
-
var
|
|
35
|
-
//# sourceMappingURL=validateHookName.js.map
|
|
41
|
+
var validateHookName_default = validateHookName;
|
|
42
|
+
//# sourceMappingURL=validateHookName.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/validateHookName.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Validate a hookName string.\n *\n * @param 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 Whether the hook name is valid.\n */\nfunction validateHookName( hookName: string ): boolean {\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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,SAAS,iBAAkB,UAA4B;AACtD,MAAK,aAAa,OAAO,YAAY,OAAO,UAAW;AAEtD,YAAQ,MAAO,2CAA4C;AAC3D,WAAO;AAAA,EACR;AAEA,MAAK,MAAM,KAAM,QAAS,GAAI;AAE7B,YAAQ,MAAO,uCAAwC;AACvD,WAAO;AAAA,EACR;AAEA,MAAK,CAAE,4BAA4B,KAAM,QAAS,GAAI;AAErD,YAAQ;AAAA,MACP;AAAA,IACD;AACA,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAEA,IAAO,2BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var validateNamespace_exports = {};
|
|
20
|
+
__export(validateNamespace_exports, {
|
|
21
|
+
default: () => validateNamespace_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Validate a namespace string.
|
|
9
|
-
*
|
|
10
|
-
* @param namespace The namespace to validate - should take the form
|
|
11
|
-
* `vendor/plugin/function`.
|
|
12
|
-
*
|
|
13
|
-
* @return Whether the namespace is valid.
|
|
14
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(validateNamespace_exports);
|
|
15
24
|
function validateNamespace(namespace) {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
console.error('The namespace must be a non-empty string.');
|
|
25
|
+
if ("string" !== typeof namespace || "" === namespace) {
|
|
26
|
+
console.error("The namespace must be a non-empty string.");
|
|
19
27
|
return false;
|
|
20
28
|
}
|
|
21
29
|
if (!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(namespace)) {
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
console.error(
|
|
31
|
+
"The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."
|
|
32
|
+
);
|
|
24
33
|
return false;
|
|
25
34
|
}
|
|
26
35
|
return true;
|
|
27
36
|
}
|
|
28
|
-
var
|
|
29
|
-
//# sourceMappingURL=validateNamespace.js.map
|
|
37
|
+
var validateNamespace_default = validateNamespace;
|
|
38
|
+
//# sourceMappingURL=validateNamespace.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/validateNamespace.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Validate a namespace string.\n *\n * @param namespace The namespace to validate - should take the form\n * `vendor/plugin/function`.\n *\n * @return Whether the namespace is valid.\n */\nfunction validateNamespace( namespace: string ): boolean {\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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,SAAS,kBAAmB,WAA6B;AACxD,MAAK,aAAa,OAAO,aAAa,OAAO,WAAY;AAExD,YAAQ,MAAO,2CAA4C;AAC3D,WAAO;AAAA,EACR;AAEA,MAAK,CAAE,+BAA+B,KAAM,SAAU,GAAI;AAEzD,YAAQ;AAAA,MACP;AAAA,IACD;AACA,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAEA,IAAO,4BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import validateNamespace from './validateNamespace';
|
|
5
|
-
import validateHookName from './validateHookName';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* Adds the hook to the appropriate hooks container.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Returns a function which, when invoked, will add a hook.
|
|
14
|
-
*
|
|
15
|
-
* @param hooks Hooks instance.
|
|
16
|
-
* @param storeKey
|
|
17
|
-
*
|
|
18
|
-
* @return Function that adds a new hook.
|
|
19
|
-
*/
|
|
1
|
+
import validateNamespace from "./validateNamespace";
|
|
2
|
+
import validateHookName from "./validateHookName";
|
|
20
3
|
function createAddHook(hooks, storeKey) {
|
|
21
4
|
return function addHook(hookName, namespace, callback, priority = 10) {
|
|
22
5
|
const hooksStore = hooks[storeKey];
|
|
@@ -26,25 +9,18 @@ function createAddHook(hooks, storeKey) {
|
|
|
26
9
|
if (!validateNamespace(namespace)) {
|
|
27
10
|
return;
|
|
28
11
|
}
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
console.error('The hook callback must be a function.');
|
|
12
|
+
if ("function" !== typeof callback) {
|
|
13
|
+
console.error("The hook callback must be a function.");
|
|
32
14
|
return;
|
|
33
15
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
console.error('If specified, the hook priority must be a number.');
|
|
16
|
+
if ("number" !== typeof priority) {
|
|
17
|
+
console.error(
|
|
18
|
+
"If specified, the hook priority must be a number."
|
|
19
|
+
);
|
|
39
20
|
return;
|
|
40
21
|
}
|
|
41
|
-
const handler = {
|
|
42
|
-
callback,
|
|
43
|
-
priority,
|
|
44
|
-
namespace
|
|
45
|
-
};
|
|
22
|
+
const handler = { callback, priority, namespace };
|
|
46
23
|
if (hooksStore[hookName]) {
|
|
47
|
-
// Find the correct insert index of the new hook.
|
|
48
24
|
const handlers = hooksStore[hookName].handlers;
|
|
49
25
|
let i;
|
|
50
26
|
for (i = handlers.length; i > 0; i--) {
|
|
@@ -53,33 +29,34 @@ function createAddHook(hooks, storeKey) {
|
|
|
53
29
|
}
|
|
54
30
|
}
|
|
55
31
|
if (i === handlers.length) {
|
|
56
|
-
// If append, operate via direct assignment.
|
|
57
32
|
handlers[i] = handler;
|
|
58
33
|
} else {
|
|
59
|
-
// Otherwise, insert before index via splice.
|
|
60
34
|
handlers.splice(i, 0, handler);
|
|
61
35
|
}
|
|
62
|
-
|
|
63
|
-
// We may also be currently executing this hook. If the callback
|
|
64
|
-
// we're adding would come after the current callback, there's no
|
|
65
|
-
// problem; otherwise we need to increase the execution index of
|
|
66
|
-
// any other runs by 1 to account for the added element.
|
|
67
|
-
hooksStore.__current.forEach(hookInfo => {
|
|
36
|
+
hooksStore.__current.forEach((hookInfo) => {
|
|
68
37
|
if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
|
|
69
38
|
hookInfo.currentIndex++;
|
|
70
39
|
}
|
|
71
40
|
});
|
|
72
41
|
} else {
|
|
73
|
-
// This is the first hook of its type.
|
|
74
42
|
hooksStore[hookName] = {
|
|
75
43
|
handlers: [handler],
|
|
76
44
|
runs: 0
|
|
77
45
|
};
|
|
78
46
|
}
|
|
79
|
-
if (hookName !==
|
|
80
|
-
hooks.doAction(
|
|
47
|
+
if (hookName !== "hookAdded") {
|
|
48
|
+
hooks.doAction(
|
|
49
|
+
"hookAdded",
|
|
50
|
+
hookName,
|
|
51
|
+
namespace,
|
|
52
|
+
callback,
|
|
53
|
+
priority
|
|
54
|
+
);
|
|
81
55
|
}
|
|
82
56
|
};
|
|
83
57
|
}
|
|
84
|
-
|
|
85
|
-
|
|
58
|
+
var createAddHook_default = createAddHook;
|
|
59
|
+
export {
|
|
60
|
+
createAddHook_default as default
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=createAddHook.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/createAddHook.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport validateNamespace from './validateNamespace';\nimport validateHookName from './validateHookName';\nimport type { Callback, Hooks, StoreKey } from '.';\nimport type { Handler, HookInfo } from './types';\n\n/**\n *\n * Adds the hook to the appropriate hooks container.\n */\nexport type AddHook = (\n\t/**\n\t * Name of hook to add\n\t */\n\thookName: string,\n\t/**\n\t * The unique namespace identifying the callback in the form.\n\t */\n\tnamespace: string,\n\t/**\n\t * Function to call when the hook is run.\n\t */\n\tcallback: Callback,\n\t/**\n\t * Priority of this hook\n\t */\n\tpriority?: number\n) => void;\n\n/**\n * Returns a function which, when invoked, will add a hook.\n *\n * @param hooks Hooks instance.\n * @param storeKey\n *\n * @return Function that adds a new hook.\n */\nfunction createAddHook( hooks: Hooks, storeKey: StoreKey ): AddHook {\n\treturn function addHook( hookName, namespace, callback, priority = 10 ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\tif ( ! validateHookName( hookName ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! validateNamespace( namespace ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( 'function' !== typeof callback ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'The hook callback must be a function.' );\n\t\t\treturn;\n\t\t}\n\n\t\t// Validate numeric priority\n\t\tif ( 'number' !== typeof priority ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error(\n\t\t\t\t'If specified, the hook priority must be a number.'\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst handler: Handler = { callback, priority, namespace };\n\n\t\tif ( hooksStore[ hookName ] ) {\n\t\t\t// Find the correct insert index of the new hook.\n\t\t\tconst handlers = hooksStore[ hookName ].handlers;\n\n\t\t\tlet i: number;\n\t\t\tfor ( i = handlers.length; i > 0; i-- ) {\n\t\t\t\tif ( priority >= handlers[ i - 1 ].priority ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( i === handlers.length ) {\n\t\t\t\t// If append, operate via direct assignment.\n\t\t\t\thandlers[ i ] = handler;\n\t\t\t} else {\n\t\t\t\t// Otherwise, insert before index via splice.\n\t\t\t\thandlers.splice( i, 0, handler );\n\t\t\t}\n\n\t\t\t// We may also be currently executing this hook. If the callback\n\t\t\t// we're adding would come after the current callback, there's no\n\t\t\t// problem; otherwise we need to increase the execution index of\n\t\t\t// any other runs by 1 to account for the added element.\n\t\t\thooksStore.__current.forEach( ( hookInfo: HookInfo ) => {\n\t\t\t\tif (\n\t\t\t\t\thookInfo.name === hookName &&\n\t\t\t\t\thookInfo.currentIndex >= i\n\t\t\t\t) {\n\t\t\t\t\thookInfo.currentIndex++;\n\t\t\t\t}\n\t\t\t} );\n\t\t} else {\n\t\t\t// This is the first hook of its type.\n\t\t\thooksStore[ hookName ] = {\n\t\t\t\thandlers: [ handler ],\n\t\t\t\truns: 0,\n\t\t\t};\n\t\t}\n\n\t\tif ( hookName !== 'hookAdded' ) {\n\t\t\thooks.doAction(\n\t\t\t\t'hookAdded',\n\t\t\t\thookName,\n\t\t\t\tnamespace,\n\t\t\t\tcallback,\n\t\t\t\tpriority\n\t\t\t);\n\t\t}\n\t};\n}\n\nexport default createAddHook;\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,uBAAuB;AAC9B,OAAO,sBAAsB;AAmC7B,SAAS,cAAe,OAAc,UAA8B;AACnE,SAAO,SAAS,QAAS,UAAU,WAAW,UAAU,WAAW,IAAK;AACvE,UAAM,aAAa,MAAO,QAAS;AAEnC,QAAK,CAAE,iBAAkB,QAAS,GAAI;AACrC;AAAA,IACD;AAEA,QAAK,CAAE,kBAAmB,SAAU,GAAI;AACvC;AAAA,IACD;AAEA,QAAK,eAAe,OAAO,UAAW;AAErC,cAAQ,MAAO,uCAAwC;AACvD;AAAA,IACD;AAGA,QAAK,aAAa,OAAO,UAAW;AAEnC,cAAQ;AAAA,QACP;AAAA,MACD;AACA;AAAA,IACD;AAEA,UAAM,UAAmB,EAAE,UAAU,UAAU,UAAU;AAEzD,QAAK,WAAY,QAAS,GAAI;AAE7B,YAAM,WAAW,WAAY,QAAS,EAAE;AAExC,UAAI;AACJ,WAAM,IAAI,SAAS,QAAQ,IAAI,GAAG,KAAM;AACvC,YAAK,YAAY,SAAU,IAAI,CAAE,EAAE,UAAW;AAC7C;AAAA,QACD;AAAA,MACD;AAEA,UAAK,MAAM,SAAS,QAAS;AAE5B,iBAAU,CAAE,IAAI;AAAA,MACjB,OAAO;AAEN,iBAAS,OAAQ,GAAG,GAAG,OAAQ;AAAA,MAChC;AAMA,iBAAW,UAAU,QAAS,CAAE,aAAwB;AACvD,YACC,SAAS,SAAS,YAClB,SAAS,gBAAgB,GACxB;AACD,mBAAS;AAAA,QACV;AAAA,MACD,CAAE;AAAA,IACH,OAAO;AAEN,iBAAY,QAAS,IAAI;AAAA,QACxB,UAAU,CAAE,OAAQ;AAAA,QACpB,MAAM;AAAA,MACP;AAAA,IACD;AAEA,QAAK,aAAa,aAAc;AAC/B,YAAM;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;AAEA,IAAO,wBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns a function which, when invoked, will return the name of the
|
|
7
|
-
* currently running hook, or `null` if no hook of the given type is currently
|
|
8
|
-
* running.
|
|
9
|
-
*
|
|
10
|
-
* @param hooks Hooks instance.
|
|
11
|
-
* @param storeKey
|
|
12
|
-
*
|
|
13
|
-
* @return Function that returns the current hook name or null.
|
|
14
|
-
*/
|
|
15
1
|
function createCurrentHook(hooks, storeKey) {
|
|
16
2
|
return function currentHook() {
|
|
17
|
-
var _currentArray$at$name;
|
|
18
3
|
const hooksStore = hooks[storeKey];
|
|
19
4
|
const currentArray = Array.from(hooksStore.__current);
|
|
20
|
-
return
|
|
5
|
+
return currentArray.at(-1)?.name ?? null;
|
|
21
6
|
};
|
|
22
7
|
}
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
var createCurrentHook_default = createCurrentHook;
|
|
9
|
+
export {
|
|
10
|
+
createCurrentHook_default as default
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=createCurrentHook.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/createCurrentHook.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport 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"],
|
|
5
|
+
"mappings": "AAeA,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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import validateHookName from './validateHookName';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* Returns the number of times an action has been fired.
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Returns a function which, when invoked, will return the number of times a
|
|
14
|
-
* hook has been called.
|
|
15
|
-
*
|
|
16
|
-
* @param hooks Hooks instance.
|
|
17
|
-
* @param storeKey
|
|
18
|
-
*
|
|
19
|
-
* @return Function that returns a hook's call count.
|
|
20
|
-
*/
|
|
1
|
+
import validateHookName from "./validateHookName";
|
|
21
2
|
function createDidHook(hooks, storeKey) {
|
|
22
3
|
return function didHook(hookName) {
|
|
23
4
|
const hooksStore = hooks[storeKey];
|
|
@@ -27,5 +8,8 @@ function createDidHook(hooks, storeKey) {
|
|
|
27
8
|
return hooksStore[hookName] && hooksStore[hookName].runs ? hooksStore[hookName].runs : 0;
|
|
28
9
|
};
|
|
29
10
|
}
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
var createDidHook_default = createDidHook;
|
|
12
|
+
export {
|
|
13
|
+
createDidHook_default as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=createDidHook.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/createDidHook.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport validateHookName from './validateHookName';\nimport type { Hooks, StoreKey } from './types';\n\n/**\n *\n * Returns the number of times an action has been fired.\n *\n */\nexport type DidHook = (\n\t/**\n\t * The hook name to check.\n\t */\n\thookName: string\n) => number | undefined;\n\n/**\n * Returns a function which, when invoked, will return the number of times a\n * hook has been called.\n *\n * @param hooks Hooks instance.\n * @param storeKey\n *\n * @return Function that returns a hook's call count.\n */\nfunction createDidHook( hooks: Hooks, storeKey: StoreKey ): DidHook {\n\treturn function didHook( hookName ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\tif ( ! validateHookName( hookName ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn hooksStore[ hookName ] && hooksStore[ hookName ].runs\n\t\t\t? hooksStore[ hookName ].runs\n\t\t\t: 0;\n\t};\n}\n\nexport default createDidHook;\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,sBAAsB;AAwB7B,SAAS,cAAe,OAAc,UAA8B;AACnE,SAAO,SAAS,QAAS,UAAW;AACnC,UAAM,aAAa,MAAO,QAAS;AAEnC,QAAK,CAAE,iBAAkB,QAAS,GAAI;AACrC;AAAA,IACD;AAEA,WAAO,WAAY,QAAS,KAAK,WAAY,QAAS,EAAE,OACrD,WAAY,QAAS,EAAE,OACvB;AAAA,EACJ;AACD;AAEA,IAAO,wBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,34 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns whether a hook is currently being executed.
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Returns a function which, when invoked, will return whether a hook is
|
|
12
|
-
* currently being executed.
|
|
13
|
-
*
|
|
14
|
-
* @param hooks Hooks instance.
|
|
15
|
-
* @param storeKey
|
|
16
|
-
*
|
|
17
|
-
* @return Function that returns whether a hook is currently
|
|
18
|
-
* being executed.
|
|
19
|
-
*/
|
|
20
1
|
function createDoingHook(hooks, storeKey) {
|
|
21
2
|
return function doingHook(hookName) {
|
|
22
3
|
const hooksStore = hooks[storeKey];
|
|
23
|
-
|
|
24
|
-
// If the hookName was not passed, check for any current hook.
|
|
25
|
-
if ('undefined' === typeof hookName) {
|
|
4
|
+
if ("undefined" === typeof hookName) {
|
|
26
5
|
return hooksStore.__current.size > 0;
|
|
27
6
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
7
|
+
return Array.from(hooksStore.__current).some(
|
|
8
|
+
(hook) => hook.name === hookName
|
|
9
|
+
);
|
|
31
10
|
};
|
|
32
11
|
}
|
|
33
|
-
|
|
34
|
-
|
|
12
|
+
var createDoingHook_default = createDoingHook;
|
|
13
|
+
export {
|
|
14
|
+
createDoingHook_default as default
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=createDoingHook.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/createDoingHook.ts"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": "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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* Returns whether any handlers are attached for the given hookName and optional namespace.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Returns a function which, when invoked, will return whether any handlers are
|
|
12
|
-
* attached to a particular hook.
|
|
13
|
-
*
|
|
14
|
-
* @param hooks Hooks instance.
|
|
15
|
-
* @param storeKey
|
|
16
|
-
*
|
|
17
|
-
* @return Function that returns whether any handlers are
|
|
18
|
-
* attached to a particular hook and optional namespace.
|
|
19
|
-
*/
|
|
20
1
|
function createHasHook(hooks, storeKey) {
|
|
21
2
|
return function hasHook(hookName, namespace) {
|
|
22
3
|
const hooksStore = hooks[storeKey];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
if ("undefined" !== typeof namespace) {
|
|
5
|
+
return hookName in hooksStore && hooksStore[hookName].handlers.some(
|
|
6
|
+
(hook) => hook.namespace === namespace
|
|
7
|
+
);
|
|
27
8
|
}
|
|
28
9
|
return hookName in hooksStore;
|
|
29
10
|
};
|
|
30
11
|
}
|
|
31
|
-
|
|
32
|
-
|
|
12
|
+
var createHasHook_default = createHasHook;
|
|
13
|
+
export {
|
|
14
|
+
createHasHook_default as default
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=createHasHook.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/createHasHook.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { Hooks, StoreKey } from './types';\n/**\n *\n * Returns whether any handlers are attached for the given hookName and optional namespace.\n */\nexport type HasHook = (\n\t/**\n\t * The name of the hook to check for.\n\t */\n\thookname: string,\n\t/**\n\t * The unique namespace identifying the callback in the form `vendor/plugin/function`.\n\t */\n\tnamespace?: string\n) => boolean;\n\n/**\n * Returns a function which, when invoked, will return whether any handlers are\n * attached to a particular hook.\n *\n * @param hooks Hooks instance.\n * @param storeKey\n *\n * @return Function that returns whether any handlers are\n * attached to a particular hook and optional namespace.\n */\nfunction createHasHook( hooks: Hooks, storeKey: StoreKey ): HasHook {\n\treturn function hasHook( hookName, namespace ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\t// Use the namespace if provided.\n\t\tif ( 'undefined' !== typeof namespace ) {\n\t\t\treturn (\n\t\t\t\thookName in hooksStore &&\n\t\t\t\thooksStore[ hookName ].handlers.some(\n\t\t\t\t\t( hook ) => hook.namespace === namespace\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn hookName in hooksStore;\n\t};\n}\n\nexport default createHasHook;\n"],
|
|
5
|
+
"mappings": "AA6BA,SAAS,cAAe,OAAc,UAA8B;AACnE,SAAO,SAAS,QAAS,UAAU,WAAY;AAC9C,UAAM,aAAa,MAAO,QAAS;AAGnC,QAAK,gBAAgB,OAAO,WAAY;AACvC,aACC,YAAY,cACZ,WAAY,QAAS,EAAE,SAAS;AAAA,QAC/B,CAAE,SAAU,KAAK,cAAc;AAAA,MAChC;AAAA,IAEF;AAEA,WAAO,YAAY;AAAA,EACpB;AACD;AAEA,IAAO,wBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|