Skip to content

It is not a ponyfill! #184

Open
Open
@iegik

Description

@iegik

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

https://xhr.spec.whatwg.org/#the-abort()-method


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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions