我正在为 Javascript 开发人员查看 A First Reason React 应用程序中的 Reason 示例
我看到他Js.Promise.resolve
在使用时正在打电话bs-fetch
:
RepoData.fetchRepos()
|> Js.Promise.then_(repoData => {
handleReposLoaded(repoData);
Js.Promise.resolve();
})
|> ignore;
我也在 BuckleScript 代码中看到了类似的代码。例如在Bucklescript Cookbook中:
Js.Promise.(
Fetch.fetch "https://api.github.com/users/reasonml-community/repos"
|> then_ Fetch.Response.text
|> then_ (fun text ->
text
|> names
|> Array.iter Js.log
|> resolve)
|> ignore
在 JS 中,我们通常resolve
在创建新的 Promise 时调用,而不是在使用返回 Promise 的函数时调用。那么为什么我们需要resolve
在上述情况下调用呢?