Skip to content

Commit 9bce879

Browse files
committed
Use noop as next middleware in the last middleware in the stack
1 parent 8c693d3 commit 9bce879

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api-fetch/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"@babel/runtime": "^7.0.0",
2525
"@wordpress/hooks": "file:../hooks",
2626
"@wordpress/i18n": "file:../i18n",
27-
"@wordpress/url": "file:../url"
27+
"@wordpress/url": "file:../url",
28+
"lodash": "^4.17.10"
2829
},
2930
"publishConfig": {
3031
"access": "public"

packages/api-fetch/src/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { noop } from 'lodash';
5+
16
/**
27
* WordPress dependencies
38
*/
@@ -136,14 +141,15 @@ function apiFetch( options ) {
136141

137142
const runMiddleware = ( index ) => ( nextOptions ) => {
138143
const nextMiddleware = steps[ index ];
144+
let next;
139145

140146
if ( steps.length > ( index + 1 ) ) {
141-
const next = runMiddleware( index + 1 );
142-
return nextMiddleware( nextOptions, next );
147+
next = runMiddleware( index + 1 );
148+
} else {
149+
next = noop;
143150
}
144151

145-
// Next middleware is the last one, so no next arg is passed
146-
return nextMiddleware( nextOptions );
152+
return nextMiddleware( nextOptions, next );
147153
};
148154

149155
return runMiddleware( 0 )( options );

packages/api-fetch/src/test/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { noop } from 'lodash';
5+
16
/**
27
* Internal dependencies
38
*/
@@ -193,6 +198,6 @@ describe( 'apiFetch', () => {
193198

194199
expect( window.fetch ).not.toHaveBeenCalled();
195200

196-
expect( customFetchHandler ).toHaveBeenCalledWith( { path: '/random?_locale=user' } );
201+
expect( customFetchHandler ).toHaveBeenCalledWith( { path: '/random?_locale=user' }, noop );
197202
} );
198203
} );

0 commit comments

Comments
 (0)