-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
createDidHook.js
31 lines (27 loc) · 760 Bytes
/
createDidHook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import validateHookName from './validateHookName.js';
/**
* Returns a function which, when invoked, will return the number of times a
* hook has been called.
*
* @param {Object} hooks Stored hooks, keyed by hook name.
*
* @return {Function} Function that returns a hook's call count.
*/
function createDidHook( hooks ) {
/**
* Returns the number of times an action has been fired.
*
* @param {string} hookName The hook name to check.
*
* @return {number} The number of times the hook has run.
*/
return function didHook( hookName ) {
if ( ! validateHookName( hookName ) ) {
return;
}
return hooks[ hookName ] && hooks[ hookName ].runs
? hooks[ hookName ].runs
: 0;
};
}
export default createDidHook;