Skip to content

Conversation

kadamwhite
Copy link
Collaborator

@kadamwhite kadamwhite commented Jul 5, 2019

This PR implements a new transport using the browser-oriented fetch method, rather than our existing Node-oriented approach with superagent. At present we're using isomorphic-unfetch to provide the fetch behavior in a Node- and browser-compatible way.

  • Implement basic fetch transport
  • Implement media upload handling
  • Test in browser
  • Resolve pending issue with transport method wrapping (see TODO comment)
  • Resolve pending issue with error states (see TODO comment)
  • (Extracted into Optimize browser bundle for wpapi/fetch #443) Possibly alias out fetch and form-data to avoid bloating browser build?
@kadamwhite kadamwhite changed the title Implement fetch transport WIP: Implement fetch transport Jul 5, 2019
kadamwhite added 15 commits July 5, 2019 18:21
This will simplify iteration & testing of the updated browser builds
isomorphic-unfetch is just a wrapper for node-fetch in Node, and in the browser we leave polyfilling as an exercise for the viewer. No need to ship the intermediary if we are not using its isomorphism.
Cleans up tests following removal of that library in 347e4ee
Because of how transports were previously all bound using the single shared WPAPI constructor, all tests which purported to set the transport only for one transport-specific constructor in fact all shared whichever transport was set last. To work around this, the bindTransport method has been enhanced to subclass WPAPI, and the definition of the discover method has therefore moved into that function, rather than the base wpapi.js .site() is useful regardless of whether a transport is present, so it remains in the base class; however, we override .site() with a version which provides instances of the new transport-specific subclasses when creating a new version of the constructor in bindTransport(). As a plus, this fixes the issues we had in the transport binding tests! Turns out that wasn't a false negative after all.
@kadamwhite kadamwhite force-pushed the implement-fetch-transport branch from 5e0456c to 2f06556 Compare October 20, 2019 14:51
@kadamwhite kadamwhite changed the title WIP: Implement fetch transport Implement fetch transport Oct 21, 2019
@kadamwhite kadamwhite merged commit f4a23a9 into master Oct 21, 2019
@kadamwhite kadamwhite deleted the implement-fetch-transport branch October 21, 2019 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant