Javascript 在 react-flux 中获取 API

Javascript fetch API in react-flux

我正在研究 flux-react-router-example by @Dan Abramov, I notice in the Fetch API code here:fetch API 有一个 return 承诺,里面有一个嵌套的 return:

return fetch(url).then(response =>
response.json().then(json => {
  const camelizedJson = camelizeKeys(json);
  const nextPageUrl = getNextPageUrl(response) || undefined;

  return {
    ...normalize(camelizedJson, schema),
    nextPageUrl
  };
})

);

我对这个嵌套的 return 感到困惑,为什么在这里使用这个?为什么不只是 return response.json()?

好像如果我做同样的事情,我会得到一个未定义的值

从响应中检索到的 json 是

  1. 使用 humps
  2. 转换为驼峰式大小写
  3. un-nested 使用 normalizr 与 redux store
  4. 结合使用更容易处理
  5. 充实了下一页url,解析自linkheader

关于为什么在存储中存储嵌套响应 objects 通常不是一个好主意的更多讨论和推理可以在 React JS Google Group.

中找到