Description
Whats the difference between Ponyfill and Polyfill?
Polyfill - checks if functionality is not available and add it:
if (!String.prototype.trim) String.prototype.trim = ...
Ponyfill - just the adds own same functionality:
function trim(){...}
import { trim } from '...'
What about whatwg-fetch on this project?
whatwg-fetch is Polyfill, but on acts like Ponyfill. Why?
WARNING: On the build phase global this is passed without fetch, so it hardcoded to overwrite the fetch function!!!!
https://github.com/lquixada/cross-fetch/blob/v4.x/rollup.config.js
This will cause some unexpected behaviour of the fetch function.
For example, it throws an Error when request is aborted. Should it?
Abort should not throw the error:
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
It returns a Promise that resolves to the Response to that request — as soon as the server responds with headers — even if the server response is an HTTP error status.
At the heart of Fetch are the Interface abstractions of HTTP Requests, Responses, and Headers, along with a fetch() method for initiating asynchronous resource requests
Fetch takes the asynchronous nature of such requests one step further. The API is completely Promise-based
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Basic_concepts#in_a_nutshell
- If this’s state is opened with this’s send() flag set, headers received, or loading, then run the request error steps for this and abort.
- If this’s state is done, then set this’s state to unsent and this’s response to a network error.
- If xhr’s synchronous flag is set, then throw exception.
In other words, it should fire the 'abort' event and cancels the request and DO NOT throw an error. Because fetch is asynchronous*
fetch is asynchronous, based on Promise, but resolved only when response is received.