@wordpress/hooks
Advanced tools
Comparing version 2.11.1 to 2.12.1-next.53e2173694.0
@@ -38,23 +38,22 @@ /** | ||
var _createHooks = createHooks(), | ||
addAction = _createHooks.addAction, | ||
addFilter = _createHooks.addFilter, | ||
removeAction = _createHooks.removeAction, | ||
removeFilter = _createHooks.removeFilter, | ||
hasAction = _createHooks.hasAction, | ||
hasFilter = _createHooks.hasFilter, | ||
removeAllActions = _createHooks.removeAllActions, | ||
removeAllFilters = _createHooks.removeAllFilters, | ||
doAction = _createHooks.doAction, | ||
applyFilters = _createHooks.applyFilters, | ||
currentAction = _createHooks.currentAction, | ||
currentFilter = _createHooks.currentFilter, | ||
doingAction = _createHooks.doingAction, | ||
doingFilter = _createHooks.doingFilter, | ||
didAction = _createHooks.didAction, | ||
didFilter = _createHooks.didFilter, | ||
actions = _createHooks.actions, | ||
filters = _createHooks.filters; | ||
export var defaultHooks = createHooks(); | ||
var addAction = defaultHooks.addAction, | ||
addFilter = defaultHooks.addFilter, | ||
removeAction = defaultHooks.removeAction, | ||
removeFilter = defaultHooks.removeFilter, | ||
hasAction = defaultHooks.hasAction, | ||
hasFilter = defaultHooks.hasFilter, | ||
removeAllActions = defaultHooks.removeAllActions, | ||
removeAllFilters = defaultHooks.removeAllFilters, | ||
doAction = defaultHooks.doAction, | ||
applyFilters = defaultHooks.applyFilters, | ||
currentAction = defaultHooks.currentAction, | ||
currentFilter = defaultHooks.currentFilter, | ||
doingAction = defaultHooks.doingAction, | ||
doingFilter = defaultHooks.doingFilter, | ||
didAction = defaultHooks.didAction, | ||
didFilter = defaultHooks.didFilter, | ||
actions = defaultHooks.actions, | ||
filters = defaultHooks.filters; | ||
export { createHooks, addAction, addFilter, removeAction, removeFilter, hasAction, hasFilter, removeAllActions, removeAllFilters, doAction, applyFilters, currentAction, currentFilter, doingAction, doingFilter, didAction, didFilter, actions, filters }; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,28 @@ | ||
/** @typedef {(...args: any[])=>any} Callback */ | ||
/** | ||
* @typedef Handler | ||
* @property {Callback} callback The callback | ||
* @property {string} namespace The namespace | ||
* @property {number} priority The namespace | ||
*/ | ||
/** | ||
* @typedef Hook | ||
* @property {Handler[]} handlers Array of handlers | ||
* @property {number} runs Run counter | ||
*/ | ||
/** | ||
* @typedef Current | ||
* @property {string} name Hook name | ||
* @property {number} currentIndex The index | ||
*/ | ||
/** | ||
* @typedef {Record<string, Hook> & {__current: Current[]}} Store | ||
*/ | ||
/** | ||
* @typedef {'actions' | 'filters'} StoreKey | ||
*/ | ||
/** | ||
* @typedef {import('./createHooks').Hooks} Hooks | ||
*/ | ||
export const defaultHooks: import("./createHooks")._Hooks; | ||
export type Callback = (...args: any[]) => any; | ||
@@ -2,0 +29,0 @@ export type Handler = { |
@@ -11,8 +11,8 @@ "use strict"; | ||
get: function get() { | ||
return _createHooks2.default; | ||
return _createHooks.default; | ||
} | ||
}); | ||
exports.filters = exports.actions = exports.didFilter = exports.didAction = exports.doingFilter = exports.doingAction = exports.currentFilter = exports.currentAction = exports.applyFilters = exports.doAction = exports.removeAllFilters = exports.removeAllActions = exports.hasFilter = exports.hasAction = exports.removeFilter = exports.removeAction = exports.addFilter = exports.addAction = void 0; | ||
exports.filters = exports.actions = exports.didFilter = exports.didAction = exports.doingFilter = exports.doingAction = exports.currentFilter = exports.currentAction = exports.applyFilters = exports.doAction = exports.removeAllFilters = exports.removeAllActions = exports.hasFilter = exports.hasAction = exports.removeFilter = exports.removeAction = exports.addFilter = exports.addAction = exports.defaultHooks = void 0; | ||
var _createHooks2 = _interopRequireDefault(require("./createHooks")); | ||
var _createHooks = _interopRequireDefault(require("./createHooks")); | ||
@@ -55,22 +55,22 @@ /** | ||
*/ | ||
var _createHooks = (0, _createHooks2.default)(), | ||
addAction = _createHooks.addAction, | ||
addFilter = _createHooks.addFilter, | ||
removeAction = _createHooks.removeAction, | ||
removeFilter = _createHooks.removeFilter, | ||
hasAction = _createHooks.hasAction, | ||
hasFilter = _createHooks.hasFilter, | ||
removeAllActions = _createHooks.removeAllActions, | ||
removeAllFilters = _createHooks.removeAllFilters, | ||
doAction = _createHooks.doAction, | ||
applyFilters = _createHooks.applyFilters, | ||
currentAction = _createHooks.currentAction, | ||
currentFilter = _createHooks.currentFilter, | ||
doingAction = _createHooks.doingAction, | ||
doingFilter = _createHooks.doingFilter, | ||
didAction = _createHooks.didAction, | ||
didFilter = _createHooks.didFilter, | ||
actions = _createHooks.actions, | ||
filters = _createHooks.filters; | ||
var defaultHooks = (0, _createHooks.default)(); | ||
exports.defaultHooks = defaultHooks; | ||
var addAction = defaultHooks.addAction, | ||
addFilter = defaultHooks.addFilter, | ||
removeAction = defaultHooks.removeAction, | ||
removeFilter = defaultHooks.removeFilter, | ||
hasAction = defaultHooks.hasAction, | ||
hasFilter = defaultHooks.hasFilter, | ||
removeAllActions = defaultHooks.removeAllActions, | ||
removeAllFilters = defaultHooks.removeAllFilters, | ||
doAction = defaultHooks.doAction, | ||
applyFilters = defaultHooks.applyFilters, | ||
currentAction = defaultHooks.currentAction, | ||
currentFilter = defaultHooks.currentFilter, | ||
doingAction = defaultHooks.doingAction, | ||
doingFilter = defaultHooks.doingFilter, | ||
didAction = defaultHooks.didAction, | ||
didFilter = defaultHooks.didFilter, | ||
actions = defaultHooks.actions, | ||
filters = defaultHooks.filters; | ||
exports.filters = filters; | ||
@@ -77,0 +77,0 @@ exports.actions = actions; |
@@ -5,2 +5,8 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. --> | ||
## 2.12.0-next.0 (2021-03-11) | ||
### New Feature | ||
- Export the default `createHooks` singleton instance as `defaultHooks`, in addition to exporting the individual methods. | ||
## 2.11.0 (2020-12-17) | ||
@@ -7,0 +13,0 @@ |
{ | ||
"name": "@wordpress/hooks", | ||
"version": "2.11.1", | ||
"version": "2.12.1-next.53e2173694.0", | ||
"description": "WordPress hooks library.", | ||
@@ -31,3 +31,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "c79ef3aaa212f328a7d45f02018c21c94aa0965c" | ||
"gitHead": "cac63ac5e871791c3ea5bc6a5a7dd06d6229cccb" | ||
} |
@@ -25,4 +25,10 @@ # Hooks | ||
In the WordPress context, API functions can be called via the global `wp.hooks` like this `wp.hooks.addAction()`, etc. One notable difference from the PHP API is that `addAction()` and `addFilter()` also need to include a namespace as the second argument. | ||
#### The global instance | ||
In the above example, we are creating a custom instance of the `Hooks` object and registering hooks there. The package also creates a default global instance that's accessible through the `defaultHooks` named exports, and its methods are also separately exported one-by-one. | ||
In the WordPress context, that enables API functions to be called via the global `wp.hooks` object, like `wp.hooks.addAction()`, etc. | ||
One notable difference between the JS and PHP hooks API is that in the JS version, `addAction()` and `addFilter()` also need to include a namespace as the second argument. | ||
### API Usage | ||
@@ -47,2 +53,3 @@ | ||
* `filters` | ||
* `defaultHooks` | ||
@@ -49,0 +56,0 @@ |
@@ -39,2 +39,4 @@ /** | ||
export const defaultHooks = createHooks(); | ||
const { | ||
@@ -59,3 +61,3 @@ addAction, | ||
filters, | ||
} = createHooks(); | ||
} = defaultHooks; | ||
@@ -62,0 +64,0 @@ export { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
207134
2730
67
1