javascript-tutorial / javascript-tutorial/en.javascript.info
Promise basics loading indicator example
未关闭
还没有人认领这个 Issue。
- 主要语言
- HTML
- 星标
- 25.5k
- 派生
- 4k
- PR 合并指标
- 30 天内没有已合并 PR
描述
So I was wrapping my head around why would the loading indicator stay active if the promise was settled? The solution did not clarify everything for me, the best explanation I found is:
new Promise((resolve, reject) => {
/* do something that takes time, and then call resolve or maybe reject */
const loading = document.createElement('img');
loading.src="https://media3.giphy.com/media/3oEjI6SIIHBdRxXI40/giphy.gif?cid=ecf05e471sfq2igav6mmdj3cvn1mr4j6br7k3tmo4jvg5t5u&rid=giphy.gif&ct=g";
document.body.append(loading);
})
*!*
// runs when the promise is settled, doesn't matter successfully or not
doSomething().finally(() => loading.remove());
// so the loading indicator is always stopped before we go on
*/!*
.then(result => show result, err => show error)
Could something like this improve the example?
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先找到 issue 中讨论的 Promise basics 加载指示器示例,并检查它如何解释已 settled 的 promise。将该示例与提议的基于 finally 的清理进行比较,然后在这能使行为更清晰的情况下更新教程,并验证说明涵盖成功和 rejected 的 promise。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100