@wordpress/hooks
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -0,1 +1,3 @@ | ||
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; | ||
/** | ||
@@ -30,4 +32,11 @@ * Returns a function which, when invoked, will execute all callbacks | ||
hooks[hookName].runs++; | ||
var handlers = hooks[hookName].handlers; | ||
var handlers = hooks[hookName].handlers; // The following code is stripped from production builds. | ||
if ('production' !== process.env.NODE_ENV) { | ||
// Handle any 'all' hooks registered. | ||
if ('hookAdded' !== hookName && hooks.all) { | ||
handlers.push.apply(handlers, _toConsumableArray(hooks.all.handlers)); | ||
} | ||
} | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -34,0 +43,0 @@ args[_key - 1] = arguments[_key]; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,2 +10,4 @@ value: true | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
/** | ||
@@ -38,4 +42,11 @@ * Returns a function which, when invoked, will execute all callbacks | ||
hooks[hookName].runs++; | ||
var handlers = hooks[hookName].handlers; | ||
var handlers = hooks[hookName].handlers; // The following code is stripped from production builds. | ||
if ('production' !== process.env.NODE_ENV) { | ||
// Handle any 'all' hooks registered. | ||
if ('hookAdded' !== hookName && hooks.all) { | ||
handlers.push.apply(handlers, (0, _toConsumableArray2.default)(hooks.all.handlers)); | ||
} | ||
} | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -42,0 +53,0 @@ args[_key - 1] = arguments[_key]; |
@@ -0,1 +1,7 @@ | ||
## Master | ||
### New Feature | ||
- Enable support for the 'all' hook in non production environments. | ||
## 2.0.4 (2019-01-03) | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "@wordpress/hooks", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "WordPress hooks library.", | ||
@@ -29,3 +29,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "87f92f8f58a14a58b44beff0919734c546b3b975" | ||
"gitHead": "256d514d356709cfdb27e28a5b200043d768d9cc" | ||
} |
@@ -55,2 +55,6 @@ # Hooks | ||
### The `all` hook | ||
In non-minified builds developers can register a filter or action that will be called on *all* hooks, for example: `addAction( 'all', 'namespace', callbackFunction );`. Useful for debugging, the code supporting the `all` hook is stripped from the production code for performance reasons. | ||
<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p> |
@@ -33,2 +33,10 @@ /** | ||
// The following code is stripped from production builds. | ||
if ( 'production' !== process.env.NODE_ENV ) { | ||
// Handle any 'all' hooks registered. | ||
if ( 'hookAdded' !== hookName && hooks.all ) { | ||
handlers.push( ...hooks.all.handlers ); | ||
} | ||
} | ||
if ( ! handlers || ! handlers.length ) { | ||
@@ -35,0 +43,0 @@ return returnFirstArg ? |
@@ -80,2 +80,3 @@ /* eslint-disable no-console */ | ||
} | ||
delete hooks.all; | ||
} ); | ||
@@ -701,1 +702,45 @@ } ); | ||
} ); | ||
test( 'add an all filter and run it any hook to trigger it', () => { | ||
addFilter( 'all', 'my_callback', filterA ); | ||
expect( applyFilters( 'test.filter', 'test' ) ).toBe( 'testa' ); | ||
expect( applyFilters( 'test.filter-anything', 'test' ) ).toBe( 'testa' ); | ||
} ); | ||
test( 'add an all action and run it any hook to trigger it', () => { | ||
addAction( 'all', 'my_callback', actionA ); | ||
addAction( 'test.action', 'my_callback', actionA );// Doesn't get triggered. | ||
doAction( 'test.action-anything' ); | ||
expect( window.actionValue ).toBe( 'a' ); | ||
} ); | ||
test( 'add multiple all filters and run it any hook to trigger them', () => { | ||
addFilter( 'all', 'my_callback', filterA ); | ||
addFilter( 'all', 'my_callback', filterB ); | ||
expect( applyFilters( 'test.filter', 'test' ) ).toBe( 'testab' ); | ||
expect( applyFilters( 'test.filter-anything', 'test' ) ).toBe( 'testab' ); | ||
} ); | ||
test( 'add multiple all actions and run it any hook to trigger them', () => { | ||
addAction( 'all', 'my_callback', actionA ); | ||
addAction( 'all', 'my_callback', actionB ); | ||
addAction( 'test.action', 'my_callback', actionA ); // Doesn't get triggered. | ||
doAction( 'test.action-anything' ); | ||
expect( window.actionValue ).toBe( 'ab' ); | ||
} ); | ||
test( 'add multiple all filters and run it any hook to trigger them by priority', () => { | ||
addFilter( 'all', 'my_callback', filterA, 11 ); | ||
addFilter( 'all', 'my_callback', filterB, 10 ); | ||
expect( applyFilters( 'test.filter', 'test' ) ).toBe( 'testba' ); | ||
expect( applyFilters( 'test.filter-anything', 'test' ) ).toBe( 'testba' ); | ||
} ); | ||
test( 'add multiple all actions and run it any hook to trigger them by priority', () => { | ||
addAction( 'all', 'my_callback', actionA, 11 ); | ||
addAction( 'all', 'my_callback', actionB, 10 ); | ||
addAction( 'test.action', 'my_callback', actionA ); // Doesn't get triggered. | ||
doAction( 'test.action-anything' ); | ||
expect( window.actionValue ).toBe( 'ba' ); | ||
} ); | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
149877
2054
60
2