@wordpress/hooks
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -6,15 +6,45 @@ const Benchmark = require( 'benchmark' ); | ||
function myCallback() {} | ||
const filter = process.argv[ 2 ]; | ||
const isInFilter = ( key ) => ! filter || filter === key; | ||
hooks.addFilter( 'handled', 'myCallback', myCallback ); | ||
function reset() { | ||
hooks.removeAllFilters( 'example' ); | ||
hooks.removeAllActions( 'example' ); | ||
} | ||
if ( isInFilter( 'applyFilters' ) ) { | ||
function myCallback() {} | ||
hooks.addFilter( 'example', 'myCallback', myCallback ); | ||
suite | ||
.add( 'applyFilters - handled', () => { | ||
hooks.applyFilters( 'handled' ); | ||
} ) | ||
.add( 'applyFilters - unhandled', () => { | ||
hooks.applyFilters( 'unhandled' ); | ||
} ); | ||
} | ||
if ( isInFilter( 'addFilter' ) ) { | ||
let hasSetHighPriority = false; | ||
suite | ||
.add( 'addFilter - append last', () => { | ||
hooks.addFilter( 'example', 'myCallback', () => {} ); | ||
} ) | ||
.add( 'addFilter - default before higher priority', () => { | ||
if ( ! hasSetHighPriority ) { | ||
hasSetHighPriority = true; | ||
hooks.addFilter( 'example', 'priority', () => {}, 20 ); | ||
} | ||
hooks.addFilter( 'example', 'myCallback', () => {} ); | ||
} ); | ||
} | ||
suite | ||
.add( 'handled', () => { | ||
hooks.applyFilters( 'handled' ); | ||
} ) | ||
.add( 'unhandled', () => { | ||
hooks.applyFilters( 'unhandled' ); | ||
} ) | ||
.on( 'cycle', reset ) | ||
// eslint-disable-next-line no-console | ||
.on( 'cycle', ( event ) => console.log( event.target.toString() ) ) | ||
.run( { async: true } ); |
@@ -54,14 +54,17 @@ import validateNamespace from './validateNamespace.js'; | ||
var handlers = hooks[hookName].handlers; | ||
var i = 0; | ||
var i; | ||
while (i < handlers.length) { | ||
if (handlers[i].priority > priority) { | ||
for (i = handlers.length; i > 0; i--) { | ||
if (priority >= handlers[i - 1].priority) { | ||
break; | ||
} | ||
} | ||
i++; | ||
} // Insert (or append) the new hook. | ||
handlers.splice(i, 0, handler); // We may also be currently executing this hook. If the callback | ||
if (i === handlers.length) { | ||
// If append, operate via direct assignment. | ||
handlers[i] = handler; | ||
} else { | ||
// Otherwise, insert before index via splice. | ||
handlers.splice(i, 0, handler); | ||
} // We may also be currently executing this hook. If the callback | ||
// we're adding would come after the current callback, there's no | ||
@@ -71,2 +74,3 @@ // problem; otherwise we need to increase the execution index of | ||
(hooks.__current || []).forEach(function (hookInfo) { | ||
@@ -73,0 +77,0 @@ if (hookInfo.name === hookName && hookInfo.currentIndex >= i) { |
@@ -65,14 +65,17 @@ "use strict"; | ||
var handlers = hooks[hookName].handlers; | ||
var i = 0; | ||
var i; | ||
while (i < handlers.length) { | ||
if (handlers[i].priority > priority) { | ||
for (i = handlers.length; i > 0; i--) { | ||
if (priority >= handlers[i - 1].priority) { | ||
break; | ||
} | ||
} | ||
i++; | ||
} // Insert (or append) the new hook. | ||
handlers.splice(i, 0, handler); // We may also be currently executing this hook. If the callback | ||
if (i === handlers.length) { | ||
// If append, operate via direct assignment. | ||
handlers[i] = handler; | ||
} else { | ||
// Otherwise, insert before index via splice. | ||
handlers.splice(i, 0, handler); | ||
} // We may also be currently executing this hook. If the callback | ||
// we're adding would come after the current callback, there's no | ||
@@ -82,2 +85,3 @@ // problem; otherwise we need to increase the execution index of | ||
(hooks.__current || []).forEach(function (hookInfo) { | ||
@@ -84,0 +88,0 @@ if (hookInfo.name === hookName && hookInfo.currentIndex >= i) { |
{ | ||
"name": "@wordpress/hooks", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "WordPress hooks library.", | ||
@@ -31,3 +31,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "308f6aa950705531ef9d360dc88bb9f4194542f5" | ||
"gitHead": "f0223019510166b34593ba197568ca760d2983e7" | ||
} |
@@ -48,11 +48,18 @@ import validateNamespace from './validateNamespace.js'; | ||
const handlers = hooks[ hookName ].handlers; | ||
let i = 0; | ||
while ( i < handlers.length ) { | ||
if ( handlers[ i ].priority > priority ) { | ||
let i; | ||
for ( i = handlers.length; i > 0; i-- ) { | ||
if ( priority >= handlers[ i - 1 ].priority ) { | ||
break; | ||
} | ||
i++; | ||
} | ||
// Insert (or append) the new hook. | ||
handlers.splice( i, 0, handler ); | ||
if ( i === handlers.length ) { | ||
// If append, operate via direct assignment. | ||
handlers[ i ] = handler; | ||
} else { | ||
// Otherwise, insert before index via splice. | ||
handlers.splice( i, 0, handler ); | ||
} | ||
// We may also be currently executing this hook. If the callback | ||
@@ -59,0 +66,0 @@ // we're adding would come after the current callback, there's no |
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
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
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
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
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
145288
1949
1