@wordpress/hooks
Advanced tools
Comparing version 1.1.5 to 1.1.6
@@ -54,3 +54,8 @@ import validateHookName from './validateHookName.js'; | ||
var handler = handlers[hookInfo.currentIndex]; | ||
args[0] = handler.callback.apply(null, args); | ||
var result = handler.callback.apply(null, args); | ||
if (returnFirstArg) { | ||
args[0] = result; | ||
} | ||
hookInfo.currentIndex++; | ||
@@ -57,0 +62,0 @@ } |
@@ -64,3 +64,8 @@ 'use strict'; | ||
var handler = handlers[hookInfo.currentIndex]; | ||
args[0] = handler.callback.apply(null, args); | ||
var result = handler.callback.apply(null, args); | ||
if (returnFirstArg) { | ||
args[0] = result; | ||
} | ||
hookInfo.currentIndex++; | ||
@@ -67,0 +72,0 @@ } |
{ | ||
"name": "@wordpress/hooks", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "WordPress Hooks library", | ||
@@ -5,0 +5,0 @@ "author": "WordPress", |
@@ -52,3 +52,8 @@ import validateHookName from './validateHookName.js'; | ||
const handler = handlers[ hookInfo.currentIndex ]; | ||
args[ 0 ] = handler.callback.apply( null, args ); | ||
const result = handler.callback.apply( null, args ); | ||
if ( returnFirstArg ) { | ||
args[ 0 ] = result; | ||
} | ||
hookInfo.currentIndex++; | ||
@@ -55,0 +60,0 @@ } |
@@ -575,2 +575,28 @@ /* eslint-disable no-console */ | ||
test( 'actions preserve arguments across handlers without return value', () => { | ||
const arg1 = { a: 10 }; | ||
const arg2 = { b: 20 }; | ||
addAction( 'test.action', 'my_callback1', ( a, b ) => { | ||
expect( a ).toBe( arg1 ); | ||
expect( b ).toBe( arg2 ); | ||
} ); | ||
addAction( 'test.action', 'my_callback2', ( a, b ) => { | ||
expect( a ).toBe( arg1 ); | ||
expect( b ).toBe( arg2 ); | ||
} ); | ||
doAction( 'test.action', arg1, arg2 ); | ||
} ); | ||
test( 'filters pass first argument across handlers', () => { | ||
addFilter( 'test.filter', 'my_callback1', ( count ) => count + 1 ); | ||
addFilter( 'test.filter', 'my_callback2', ( count ) => count + 1 ); | ||
const result = applyFilters( 'test.filter', 0 ); | ||
expect( result ).toBe( 2 ); | ||
} ); | ||
// Test adding via composition. | ||
@@ -577,0 +603,0 @@ test( 'adding hooks via composition', () => { |
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
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
70062
38
1877
0