1
我通过@丹阿布拉莫夫研究flux-react-router-example,我在提取API代码here通知API:取指令API有有内部嵌套回报回报承诺:JavaScript抓取的反应通量
return fetch(url).then(response =>
response.json().then(json => {
const camelizedJson = camelizeKeys(json);
const nextPageUrl = getNextPageUrl(response) || undefined;
return {
...normalize(camelizedJson, schema),
nextPageUrl
};
})
);
我这个嵌套的回报混为一谈,这是为什么这里使用?为什么不只是返回response.json()?
好像如果我做同样的事情,我会得到一个未定义的值
谢谢您的回答,我其实好奇的response.json()返回语句是如何工作的。据我所知,使用外 – Chrim
当该请求是使用githubs [提取](https://github.com/github/fetch)填充工具,它是基于[polyfillable份](HTTP制成这将创建一个未定义的值://github.github.io/fetch/)的whatwg抓取规范。身体的方法,如'文本()'和'JSON()'回报的承诺产生然后可以在使用标准的承诺链链接的结果 - 这是在这个例子中会发生什么。 长话短说:在'JSON的返回值()'调用是一个承诺。 – Codepunkt