@wordpress/hooks 4.32.0 → 4.32.1-next.ff1cebbba.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/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/createAddHook.js
CHANGED
|
@@ -1,57 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var createAddHook_exports = {};
|
|
30
|
+
__export(createAddHook_exports, {
|
|
31
|
+
default: () => createAddHook_default
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
/**
|
|
11
|
-
* Internal dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* Adds the hook to the appropriate hooks container.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns a function which, when invoked, will add a hook.
|
|
21
|
-
*
|
|
22
|
-
* @param hooks Hooks instance.
|
|
23
|
-
* @param storeKey
|
|
24
|
-
*
|
|
25
|
-
* @return Function that adds a new hook.
|
|
26
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(createAddHook_exports);
|
|
34
|
+
var import_validateNamespace = __toESM(require("./validateNamespace"));
|
|
35
|
+
var import_validateHookName = __toESM(require("./validateHookName"));
|
|
27
36
|
function createAddHook(hooks, storeKey) {
|
|
28
37
|
return function addHook(hookName, namespace, callback, priority = 10) {
|
|
29
38
|
const hooksStore = hooks[storeKey];
|
|
30
|
-
if (!(0,
|
|
39
|
+
if (!(0, import_validateHookName.default)(hookName)) {
|
|
31
40
|
return;
|
|
32
41
|
}
|
|
33
|
-
if (!(0,
|
|
42
|
+
if (!(0, import_validateNamespace.default)(namespace)) {
|
|
34
43
|
return;
|
|
35
44
|
}
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
console.error('The hook callback must be a function.');
|
|
45
|
+
if ("function" !== typeof callback) {
|
|
46
|
+
console.error("The hook callback must be a function.");
|
|
39
47
|
return;
|
|
40
48
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.error('If specified, the hook priority must be a number.');
|
|
49
|
+
if ("number" !== typeof priority) {
|
|
50
|
+
console.error(
|
|
51
|
+
"If specified, the hook priority must be a number."
|
|
52
|
+
);
|
|
46
53
|
return;
|
|
47
54
|
}
|
|
48
|
-
const handler = {
|
|
49
|
-
callback,
|
|
50
|
-
priority,
|
|
51
|
-
namespace
|
|
52
|
-
};
|
|
55
|
+
const handler = { callback, priority, namespace };
|
|
53
56
|
if (hooksStore[hookName]) {
|
|
54
|
-
// Find the correct insert index of the new hook.
|
|
55
57
|
const handlers = hooksStore[hookName].handlers;
|
|
56
58
|
let i;
|
|
57
59
|
for (i = handlers.length; i > 0; i--) {
|
|
@@ -60,33 +62,31 @@ function createAddHook(hooks, storeKey) {
|
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
if (i === handlers.length) {
|
|
63
|
-
// If append, operate via direct assignment.
|
|
64
65
|
handlers[i] = handler;
|
|
65
66
|
} else {
|
|
66
|
-
// Otherwise, insert before index via splice.
|
|
67
67
|
handlers.splice(i, 0, handler);
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
// We may also be currently executing this hook. If the callback
|
|
71
|
-
// we're adding would come after the current callback, there's no
|
|
72
|
-
// problem; otherwise we need to increase the execution index of
|
|
73
|
-
// any other runs by 1 to account for the added element.
|
|
74
|
-
hooksStore.__current.forEach(hookInfo => {
|
|
69
|
+
hooksStore.__current.forEach((hookInfo) => {
|
|
75
70
|
if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
|
|
76
71
|
hookInfo.currentIndex++;
|
|
77
72
|
}
|
|
78
73
|
});
|
|
79
74
|
} else {
|
|
80
|
-
// This is the first hook of its type.
|
|
81
75
|
hooksStore[hookName] = {
|
|
82
76
|
handlers: [handler],
|
|
83
77
|
runs: 0
|
|
84
78
|
};
|
|
85
79
|
}
|
|
86
|
-
if (hookName !==
|
|
87
|
-
hooks.doAction(
|
|
80
|
+
if (hookName !== "hookAdded") {
|
|
81
|
+
hooks.doAction(
|
|
82
|
+
"hookAdded",
|
|
83
|
+
hookName,
|
|
84
|
+
namespace,
|
|
85
|
+
callback,
|
|
86
|
+
priority
|
|
87
|
+
);
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
var
|
|
92
|
-
//# sourceMappingURL=createAddHook.js.map
|
|
91
|
+
var createAddHook_default = createAddHook;
|
|
92
|
+
//# 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,+BAA8B;AAC9B,8BAA6B;AAmC7B,SAAS,cAAe,OAAc,UAA8B;AACnE,SAAO,SAAS,QAAS,UAAU,WAAW,UAAU,WAAW,IAAK;AACvE,UAAM,aAAa,MAAO,QAAS;AAEnC,QAAK,KAAE,wBAAAA,SAAkB,QAAS,GAAI;AACrC;AAAA,IACD;AAEA,QAAK,KAAE,yBAAAC,SAAmB,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": ["validateHookName", "validateNamespace"]
|
|
7
|
+
}
|
|
@@ -1,30 +1,32 @@
|
|
|
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 createCurrentHook_exports = {};
|
|
20
|
+
__export(createCurrentHook_exports, {
|
|
21
|
+
default: () => createCurrentHook_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Returns a function which, when invoked, will return the name of the
|
|
13
|
-
* currently running hook, or `null` if no hook of the given type is currently
|
|
14
|
-
* running.
|
|
15
|
-
*
|
|
16
|
-
* @param hooks Hooks instance.
|
|
17
|
-
* @param storeKey
|
|
18
|
-
*
|
|
19
|
-
* @return Function that returns the current hook name or null.
|
|
20
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(createCurrentHook_exports);
|
|
21
24
|
function createCurrentHook(hooks, storeKey) {
|
|
22
25
|
return function currentHook() {
|
|
23
|
-
var _currentArray$at$name;
|
|
24
26
|
const hooksStore = hooks[storeKey];
|
|
25
27
|
const currentArray = Array.from(hooksStore.__current);
|
|
26
|
-
return
|
|
28
|
+
return currentArray.at(-1)?.name ?? null;
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
|
-
var
|
|
30
|
-
//# sourceMappingURL=createCurrentHook.js.map
|
|
31
|
+
var createCurrentHook_default = createCurrentHook;
|
|
32
|
+
//# 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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
|
+
}
|
package/build/createDidHook.js
CHANGED
|
@@ -1,38 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var createDidHook_exports = {};
|
|
30
|
+
__export(createDidHook_exports, {
|
|
31
|
+
default: () => createDidHook_default
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
/**
|
|
10
|
-
* Internal dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* Returns the number of times an action has been fired.
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns a function which, when invoked, will return the number of times a
|
|
21
|
-
* hook has been called.
|
|
22
|
-
*
|
|
23
|
-
* @param hooks Hooks instance.
|
|
24
|
-
* @param storeKey
|
|
25
|
-
*
|
|
26
|
-
* @return Function that returns a hook's call count.
|
|
27
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(createDidHook_exports);
|
|
34
|
+
var import_validateHookName = __toESM(require("./validateHookName"));
|
|
28
35
|
function createDidHook(hooks, storeKey) {
|
|
29
36
|
return function didHook(hookName) {
|
|
30
37
|
const hooksStore = hooks[storeKey];
|
|
31
|
-
if (!(0,
|
|
38
|
+
if (!(0, import_validateHookName.default)(hookName)) {
|
|
32
39
|
return;
|
|
33
40
|
}
|
|
34
41
|
return hooksStore[hookName] && hooksStore[hookName].runs ? hooksStore[hookName].runs : 0;
|
|
35
42
|
};
|
|
36
43
|
}
|
|
37
|
-
var
|
|
38
|
-
//# sourceMappingURL=createDidHook.js.map
|
|
44
|
+
var createDidHook_default = createDidHook;
|
|
45
|
+
//# 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,8BAA6B;AAwB7B,SAAS,cAAe,OAAc,UAA8B;AACnE,SAAO,SAAS,QAAS,UAAW;AACnC,UAAM,aAAa,MAAO,QAAS;AAEnC,QAAK,KAAE,wBAAAA,SAAkB,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": ["validateHookName"]
|
|
7
|
+
}
|
package/build/createDoingHook.js
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
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 createDoingHook_exports = {};
|
|
20
|
+
__export(createDoingHook_exports, {
|
|
21
|
+
default: () => createDoingHook_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Returns whether a hook is currently being executed.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Returns a function which, when invoked, will return whether a hook is
|
|
18
|
-
* currently being executed.
|
|
19
|
-
*
|
|
20
|
-
* @param hooks Hooks instance.
|
|
21
|
-
* @param storeKey
|
|
22
|
-
*
|
|
23
|
-
* @return Function that returns whether a hook is currently
|
|
24
|
-
* being executed.
|
|
25
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(createDoingHook_exports);
|
|
26
24
|
function createDoingHook(hooks, storeKey) {
|
|
27
25
|
return function doingHook(hookName) {
|
|
28
26
|
const hooksStore = hooks[storeKey];
|
|
29
|
-
|
|
30
|
-
// If the hookName was not passed, check for any current hook.
|
|
31
|
-
if ('undefined' === typeof hookName) {
|
|
27
|
+
if ("undefined" === typeof hookName) {
|
|
32
28
|
return hooksStore.__current.size > 0;
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
return Array.from(hooksStore.__current).some(
|
|
31
|
+
(hook) => hook.name === hookName
|
|
32
|
+
);
|
|
37
33
|
};
|
|
38
34
|
}
|
|
39
|
-
var
|
|
40
|
-
//# sourceMappingURL=createDoingHook.js.map
|
|
35
|
+
var createDoingHook_default = createDoingHook;
|
|
36
|
+
//# 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": ";;;;;;;;;;;;;;;;;;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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/createHasHook.js
CHANGED
|
@@ -1,38 +1,36 @@
|
|
|
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 createHasHook_exports = {};
|
|
20
|
+
__export(createHasHook_exports, {
|
|
21
|
+
default: () => createHasHook_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* Returns whether any handlers are attached for the given hookName and optional namespace.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Returns a function which, when invoked, will return whether any handlers are
|
|
18
|
-
* attached to a particular hook.
|
|
19
|
-
*
|
|
20
|
-
* @param hooks Hooks instance.
|
|
21
|
-
* @param storeKey
|
|
22
|
-
*
|
|
23
|
-
* @return Function that returns whether any handlers are
|
|
24
|
-
* attached to a particular hook and optional namespace.
|
|
25
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(createHasHook_exports);
|
|
26
24
|
function createHasHook(hooks, storeKey) {
|
|
27
25
|
return function hasHook(hookName, namespace) {
|
|
28
26
|
const hooksStore = hooks[storeKey];
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
if ("undefined" !== typeof namespace) {
|
|
28
|
+
return hookName in hooksStore && hooksStore[hookName].handlers.some(
|
|
29
|
+
(hook) => hook.namespace === namespace
|
|
30
|
+
);
|
|
33
31
|
}
|
|
34
32
|
return hookName in hooksStore;
|
|
35
33
|
};
|
|
36
34
|
}
|
|
37
|
-
var
|
|
38
|
-
//# sourceMappingURL=createHasHook.js.map
|
|
35
|
+
var createHasHook_default = createHasHook;
|
|
36
|
+
//# 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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
|
+
}
|