-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking: Remove support for "Node-style" error-first callbacks (#428)
Our original HTTP transport `superagent` does not use Promises by default, so all versions of this library to date have supported Node-style error-first callbacks, _e.g._ `.get( ( err, data ) => { if ( err ) {} ... } )`. However, Promises are the preferred and recommended way of using this library, and the vast majority of library consumers do not utilize the callback method signature. While evaluating additional transport providers, particularly `fetch`, it became obvious that continuing to support callback-style asynchronous methods would be cumbersome with Promise-aware, modern transport methods like `fetch` or libraries like `axios`. As part of the slimming-down of our API for Version 2, this PR removes support for the node-style callback signature on all transport methods. * Refactor superagent transport: extract bind-transport method * Remove error-first callback support from superagent transport Maintaining this node-style interface, which support threads indicate is rarely used (especially given the rising popularity of `async`/`await`), no longer outweights the benefit of providing a consistent interface regardless of the transport library used. * Update WPRequest & WPAPI for promise-only method signatures This completes the work to phase out the "node-style" error-first callbacks * Update CHANGELOG with breaking transport method signature change * Add note on callback support removal in v2 upgrade guide
- Loading branch information
1 parent
613655c
commit 8c9a2bc
Showing
12 changed files
with
130 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Utility method for binding a frozen transport object to the WPAPI constructor | ||
* | ||
* See /axios and /superagent directories | ||
* @param {Function} WPAPI The WPAPI constructor | ||
* @param {Object} httpTransport The HTTP transport object | ||
* @returns {Function} The WPAPI object augmented with the provided transport | ||
*/ | ||
module.exports = function( WPAPI, httpTransport ) { | ||
WPAPI.transport = Object.create( httpTransport ); | ||
Object.freeze( WPAPI.transport ); | ||
return WPAPI; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
"**/tests/**/*.js" | ||
], | ||
"testPathIgnorePatterns": [ | ||
"test.js", | ||
".eslintrc.js", | ||
"/tests/helpers/" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,6 @@ | ||
const WPAPI = require( '../wpapi' ); | ||
const superagentTransport = require( './superagent-transport' ); | ||
const bindTransport = require( '../lib/bind-transport' ); | ||
|
||
// Pull in superagent-based HTTP transport | ||
const httpTransport = require( './http-transport' ); | ||
|
||
/** | ||
* The HTTP transport methods object used by all WPAPI instances | ||
* | ||
* These methods may be extended or replaced on an instance-by-instance basis | ||
* | ||
* @memberof! WPAPI | ||
* @static | ||
* @property transport | ||
* @type {Object} | ||
*/ | ||
WPAPI.transport = Object.create( httpTransport ); | ||
Object.freeze( WPAPI.transport ); | ||
|
||
module.exports = WPAPI; | ||
// Bind the superagent-based HTTP transport to the WPAPI constructor | ||
module.exports = bindTransport( WPAPI, superagentTransport ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.