Warm tip: This article is reproduced from serverfault.com, please click

FilePond Options with recursive call of fetch

发布于 2021-01-13 21:27:54
FilePond.setOptions({        
    server: {            
        fetch: (url, load, error, progress, abort, headers) => {            
            fetch(url)
                .then(res => res.blob())
                .then(load);
        }

I've found this configuration online. I cannot understand why this works. Should'nt this lead to a stack-overflow?

IMO the function is calling itself recursively or am i getting anything wrong?

Questioner
Felix D.
Viewed
0
Rik 2021-01-18 16:30:02

In this example the first fetch is a property of server, the second fetch is the JavaScript native fetch function.

You could also write it like this, which maybe makes things a bit more clear?

function getData(url, load) {
  return fetch(url)
    .then(res => res.blob())
    .then(load)
}

const options = {
  server: {
    fetch: getData
  }
}

FilePond.setOptions(options);