【发布时间】:2019-03-07 02:33:35
【问题描述】:
要求:
urls = [url1, url2, url3]
并行触发所有 3 个 url 并按照 url 列表的顺序绘制 Dom
ex: Finished order of urls = [url3, url1, url2]
when url1 finishes Immediately render the DOM, without waiting for url2
If url2, url3 finishes before url1, then store url2, url3 and paint the DOM after url1 arrives
Paint the DOM with order [url1, url2, url3]
我使用 Promise 的工作:
// Fired all 3 urls at the same time
p1 = fetch(url1)
p2 = fetch(url2)
p3 = fetch(url3)
p1.then(updateDom)
.then(() => p2)
.then(updateDom)
.then(() => p3)
.then(updateDom)
我想在 Observables 中做同样的事情。
from(urls)
.pipe(
mergeMap(x => fetch(x))
)
为了并行触发它们,我使用了合并映射,但是如何对结果的顺序进行排序?
【问题讨论】:
-
我刚看了这个视频,它让我想起了这个问题youtu.be/ZdS9uOl4OJk?t=2025这里是代码codesandbox.io/s/dreamy-bas-nmw6x?file=/src/orderedMergeMap.ts
标签: rxjs system.reactive