RxJS减少不会继续 [英] RxJS reduce doesn't continue

查看:96
本文介绍了RxJS减少不会继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么flatMap不会导致下游减少?

Why doesn't the flatMap cause downstream reductions to fire?

我的代码如下:

handleFiles.flatMap(files =>
  Rx.Observable.from(files).
  flatMap((file, i) => fileReader(file, i)).
  reduce((form, file, i) => {
    form.append('file[' + i + ']', result);
    console.log('reduce step', file);
    return form;
  }, new FormData()).
  tap(console.log.bind(console, 'after reduce'))
).
subscribe(console.log.bind(console, 'response'));

问题是'after reduce'点击从未被击中。为什么?

And the problem is that the 'after reduce' tap is never hit. Why?

日志如下:

reduce step [data]
reduce step [data]

屏幕截图:

推荐答案

如果文件是数组,则reduce应终止如果从fileReader返回的observable确实如此。所以对于这段代码,问题是fileReader返回了一个没有完成的observable。

If files is an array, then reduce should terminate if the observable returned from fileReader does. So for this code, the problem was that fileReader returned an observable that didn't complete.

这篇关于RxJS减少不会继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆