Socket
Socket
Sign inDemoInstall

@wordpress/hooks

Package Overview
Dependencies
Maintainers
14
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/hooks - npm Package Compare versions

Comparing version 2.6.0 to 2.7.0

2

benchmark/index.js
const Benchmark = require( 'benchmark' );
const hooks = require( '../' );
const suite = new Benchmark.Suite;
const suite = new Benchmark.Suite();

@@ -6,0 +6,0 @@ const filter = process.argv[ 2 ];

@@ -1,2 +0,2 @@

## Master
## 2.6.0 (2019-08-29)

@@ -3,0 +3,0 @@ ### New Feature

### WordPress - Web publishing software
Copyright 2011-2019 by the contributors
Copyright 2011-2020 by the contributors

@@ -5,0 +5,0 @@ This program is free software; you can redistribute it and/or modify

{
"name": "@wordpress/hooks",
"version": "2.6.0",
"version": "2.7.0",
"description": "WordPress hooks library.",

@@ -24,3 +24,3 @@ "author": "The WordPress Contributors",

"dependencies": {
"@babel/runtime": "^7.4.4"
"@babel/runtime": "^7.8.3"
},

@@ -30,3 +30,3 @@ "publishConfig": {

},
"gitHead": "989502eccaadee1ea7666d6d9fb9f4d08b274546"
"gitHead": "41fc84af285da696c65c235331ee245dfe23971d"
}

@@ -42,3 +42,5 @@ /**

// eslint-disable-next-line no-console
console.error( 'If specified, the hook priority must be a number.' );
console.error(
'If specified, the hook priority must be a number.'
);
return;

@@ -73,3 +75,6 @@ }

( hooks.__current || [] ).forEach( ( hookInfo ) => {
if ( hookInfo.name === hookName && hookInfo.currentIndex >= i ) {
if (
hookInfo.name === hookName &&
hookInfo.currentIndex >= i
) {
hookInfo.currentIndex++;

@@ -76,0 +81,0 @@ }

@@ -27,5 +27,5 @@ /**

return hooks[ hookName ] && hooks[ hookName ].runs ?
hooks[ hookName ].runs :
0;
return hooks[ hookName ] && hooks[ hookName ].runs
? hooks[ hookName ].runs
: 0;
};

@@ -32,0 +32,0 @@ }

@@ -26,5 +26,5 @@ /**

// Return the __current hook.
return hooks.__current[ 0 ] ?
hookName === hooks.__current[ 0 ].name :
false;
return hooks.__current[ 0 ]
? hookName === hooks.__current[ 0 ].name
: false;
};

@@ -31,0 +31,0 @@ }

@@ -23,4 +23,8 @@ /**

if ( 'undefined' !== typeof namespace ) {
return hookName in hooks &&
hooks[ hookName ].handlers.some( ( hook ) => hook.namespace === namespace );
return (
hookName in hooks &&
hooks[ hookName ].handlers.some(
( hook ) => hook.namespace === namespace
)
);
}

@@ -27,0 +31,0 @@

@@ -53,5 +53,3 @@ /**

for ( let i = handlers.length - 1; i >= 0; i-- ) {
if (
handlers[ i ].namespace === namespace
) {
if ( handlers[ i ].namespace === namespace ) {
handlers.splice( i, 1 );

@@ -65,3 +63,6 @@ handlersRemoved++;

( hooks.__current || [] ).forEach( ( hookInfo ) => {
if ( hookInfo.name === hookName && hookInfo.currentIndex >= i ) {
if (
hookInfo.name === hookName &&
hookInfo.currentIndex >= i
) {
hookInfo.currentIndex--;

@@ -68,0 +69,0 @@ }

@@ -42,5 +42,3 @@ /**

if ( ! handlers || ! handlers.length ) {
return returnFirstArg ?
args[ 0 ] :
undefined;
return returnFirstArg ? args[ 0 ] : undefined;
}

@@ -47,0 +45,0 @@

@@ -188,3 +188,3 @@ /**

test( 'cannot add filters with namespace containing backslash', () => {
addFilter( 'hook_name', 'i\n\v\a\l\i\d\n\a\m\e', () => null );
addFilter( 'hook_name', 'i\n\valid\name', () => null );
expect( console ).toHaveErroredWith(

@@ -241,5 +241,10 @@ 'The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.'

expect( applyFilters( 'test_order', [] ) ).toEqual(
[ '2a', '2b', '2c', '3a', '3b', '3c' ]
);
expect( applyFilters( 'test_order', [] ) ).toEqual( [
'2a',
'2b',
'2c',
'3a',
'3b',
'3c',
] );

@@ -249,5 +254,8 @@ removeFilter( 'test_order', 'my_callback_fn_2b', callbacks.fn_2b );

expect( applyFilters( 'test_order', [] ) ).toEqual(
[ '2a', '2c', '3b', '3c' ]
);
expect( applyFilters( 'test_order', [] ) ).toEqual( [
'2a',
'2c',
'3b',
'3c',
] );

@@ -267,6 +275,16 @@ addFilter( 'test_order', 'my_callback_fn_4a', callbacks.fn_4a, 4 );

// all except 2b and 3a, which we removed earlier
'1a', '1b', '1c', '1d',
'2a', '2c', '2d',
'3b', '3c', '3d',
'4a', '4b', '4c', '4d',
'1a',
'1b',
'1c',
'1d',
'2a',
'2c',
'2d',
'3b',
'3c',
'3d',
'4a',
'4b',
'4c',
'4d',
] );

@@ -327,6 +345,16 @@ } );

test( 'add a filter before the one currently executing', () => {
addFilter( 'test.filter', 'my_callback', ( outerValue ) => {
addFilter( 'test.filter', 'my_callback', ( innerValue ) => innerValue + 'a', 1 );
return outerValue + 'b';
}, 2 );
addFilter(
'test.filter',
'my_callback',
( outerValue ) => {
addFilter(
'test.filter',
'my_callback',
( innerValue ) => innerValue + 'a',
1
);
return outerValue + 'b';
},
2
);

@@ -337,6 +365,16 @@ expect( applyFilters( 'test.filter', 'test_' ) ).toBe( 'test_b' );

test( 'add a filter after the one currently executing', () => {
addFilter( 'test.filter', 'my_callback', ( outerValue ) => {
addFilter( 'test.filter', 'my_callback', ( innerValue ) => innerValue + 'b', 2 );
return outerValue + 'a';
}, 1 );
addFilter(
'test.filter',
'my_callback',
( outerValue ) => {
addFilter(
'test.filter',
'my_callback',
( innerValue ) => innerValue + 'b',
2
);
return outerValue + 'a';
},
1
);

@@ -347,6 +385,16 @@ expect( applyFilters( 'test.filter', 'test_' ) ).toBe( 'test_ab' );

test( 'add a filter immediately after the one currently executing', () => {
addFilter( 'test.filter', 'my_callback', ( outerValue ) => {
addFilter( 'test.filter', 'my_callback', ( innerValue ) => innerValue + 'b', 1 );
return outerValue + 'a';
}, 1 );
addFilter(
'test.filter',
'my_callback',
( outerValue ) => {
addFilter(
'test.filter',
'my_callback',
( innerValue ) => innerValue + 'b',
1
);
return outerValue + 'a';
},
1
);

@@ -389,3 +437,8 @@ expect( applyFilters( 'test.filter', 'test_' ) ).toBe( 'test_ab' );

addFilter( 'test.filter', 'my_callback_filter_c', filterC, 5 );
addFilter( 'test.filter', 'my_callback_filter_removes_b', filterRemovesB, 4 );
addFilter(
'test.filter',
'my_callback_filter_removes_b',
filterRemovesB,
4
);

@@ -398,3 +451,8 @@ expect( applyFilters( 'test.filter', 'test' ) ).toBe( 'testabc' );

addFilter( 'test.filter', 'my_callback_filter_b', filterB, 2 );
addFilter( 'test.filter', 'my_callback_filter_removes_b', filterRemovesB, 2 );
addFilter(
'test.filter',
'my_callback_filter_removes_b',
filterRemovesB,
2
);
addFilter( 'test.filter', 'my_callback_filter_c', filterC, 4 );

@@ -407,3 +465,8 @@

addFilter( 'test.filter', 'my_callback_filter_a', filterA, 1 );
addFilter( 'test.filter', 'my_callback_filter_c_removes_self', filterCRemovesSelf, 3 );
addFilter(
'test.filter',
'my_callback_filter_c_removes_self',
filterCRemovesSelf,
3
);
addFilter( 'test.filter', 'my_callback_filter_c', filterC, 5 );

@@ -418,3 +481,8 @@

addFilter( 'test.filter', 'my_callback_filter_c', filterC, 5 );
addFilter( 'test.filter', 'my_callback_filter_removes_c', filterRemovesC, 4 );
addFilter(
'test.filter',
'my_callback_filter_removes_c',
filterRemovesC,
4
);

@@ -428,3 +496,8 @@ expect( applyFilters( 'test.filter', 'test' ) ).toBe( 'testab' );

addFilter( 'test.filter', 'my_callback_filter_c', filterC, 4 );
addFilter( 'test.filter', 'my_callback_filter_removes_b', filterRemovesB, 2 );
addFilter(
'test.filter',
'my_callback_filter_removes_b',
filterRemovesB,
2
);

@@ -436,3 +509,8 @@ expect( applyFilters( 'test.filter', 'test' ) ).toBe( 'testac' );

addFilter( 'test.filter', 'my_callback_filter_a', filterA, 1 );
addFilter( 'test.filter', 'my_callback_filter_removes_b', filterRemovesB, 2 );
addFilter(
'test.filter',
'my_callback_filter_removes_b',
filterRemovesB,
2
);
addFilter( 'test.filter', 'my_callback_filter_b', filterB, 2 );

@@ -569,5 +647,7 @@ addFilter( 'test.filter', 'my_callback_filter_c', filterC, 4 );

expect( applyFilters( 'test.filter1', [ 'test' ] ) ).toEqual(
[ 'test', 'test.filter1', 'test.filter2' ]
);
expect( applyFilters( 'test.filter1', [ 'test' ] ) ).toEqual( [
'test',
'test.filter1',
'test.filter2',
] );

@@ -579,5 +659,12 @@ expect( currentFilter() ).toBe( null );

function removeRecurseAndAdd2( val ) {
expect( removeFilter( 'remove_and_add', 'my_callback_recurse' ) ).toBe( 1 );
expect( removeFilter( 'remove_and_add', 'my_callback_recurse' ) ).toBe(
1
);
val += '-' + applyFilters( 'remove_and_add', '' ) + '-';
addFilter( 'remove_and_add', 'my_callback_recurse', removeRecurseAndAdd2, 10 );
addFilter(
'remove_and_add',
'my_callback_recurse',
removeRecurseAndAdd2,
10
);
return val + '2';

@@ -587,3 +674,8 @@ }

addFilter( 'remove_and_add', 'my_callback', ( val ) => val + '1', 11 );
addFilter( 'remove_and_add', 'my_callback_recurse', removeRecurseAndAdd2, 12 );
addFilter(
'remove_and_add',
'my_callback_recurse',
removeRecurseAndAdd2,
12
);
addFilter( 'remove_and_add', 'my_callback', ( val ) => val + '3', 13 );

@@ -724,3 +816,3 @@ addFilter( 'remove_and_add', 'my_callback', ( val ) => val + '4', 14 );

addAction( 'all', 'my_callback', actionA );
addAction( 'test.action', 'my_callback', actionA );// Doesn't get triggered.
addAction( 'test.action', 'my_callback', actionA ); // Doesn't get triggered.
doAction( 'test.action-anything' );

@@ -727,0 +819,0 @@ expect( window.actionValue ).toBe( 'a' );

@@ -25,3 +25,5 @@ /**

// eslint-disable-next-line no-console
console.error( 'The hook name can only contain numbers, letters, dashes, periods and underscores.' );
console.error(
'The hook name can only contain numbers, letters, dashes, periods and underscores.'
);
return false;

@@ -28,0 +30,0 @@ }

@@ -18,3 +18,5 @@ /**

// eslint-disable-next-line no-console
console.error( 'The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.' );
console.error(
'The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.'
);
return false;

@@ -21,0 +23,0 @@ }

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc