This repository has been archived by the owner on Jul 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
TRY: Support an optional namespace parameter for hasAction/hasFilter #106
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1fdc9b9
Support an optional namespace parameter for hasAction/hasFilter
ebb2c1e
add tests
d8ee906
Update docblock for hasHook
a04303b
spacing cleanup
8d8881b
some instead of includes
c2823d9
remove unneeded check for hooks[ hookName ].handlers which is always …
e928084
use dot notation for namespace
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,24 @@ | |
* @param {Object} hooks Stored hooks, keyed by hook name. | ||
* | ||
* @return {Function} Function that returns whether any handlers are | ||
* attached to a particular hook. | ||
* attached to a particular hook and optional namespace. | ||
*/ | ||
function createHasHook( hooks ) { | ||
/** | ||
* Returns how many handlers are attached for the given hook. | ||
* Returns whether any handlers are attached for the given hookName and optional namespace. | ||
* | ||
* @param {string} hookName The name of the hook to check for. | ||
* @param {string} hookName The name of the hook to check for. | ||
* @param {string} namespace Optional. The unique namespace identifying the callback in the form `vendor/plugin/function`. | ||
* | ||
* @return {boolean} Whether there are handlers that are attached to the given hook. | ||
*/ | ||
return function hasHook( hookName ) { | ||
return function hasHook( hookName, namespace ) { | ||
// Use the namespace if provided. | ||
if ( 'undefined' !== typeof namespace ){ | ||
return hookName in hooks && | ||
hooks[ hookName ].handlers.some( hook => hook.namespace === namespace ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: This style of arrow function will fail ESLint when merged to Gutenberg. https://github.com/WordPress/gutenberg/blob/ef5cfe077cb54e2b74881aeb7407b9ed15ebce85/eslint/config.js#L32 |
||
} | ||
|
||
return hookName in hooks; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Regardless of whether if ( ! ( hookName in hooks ) ) {
return false;
}
if ( 'undefined' === typeof namespace ) {
return true;
}
return hooks[ hookName ].handlers.some( ( hook ) => {
return hook.namespace === namespace;
} ); |
||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: Space before opening curly brace.