Rxjs会像行为一样构成

时间:2017-05-22 05:45:33

标签: javascript rxjs

我有多个observable,我想用concat observable链接。但我需要的是像compose一样的行为,b需要得到a和c的结果b。

function a(observable) {  return observable.map()... }
function b(observable) {  return observable.map()... }
function c(observable) {  return observable.map()... }

const obs = Observable.of([...])
Observable.concat(a(obs), b(obs), c(obs)).subscribe(...)

我该怎么做?

1 个答案:

答案 0 :(得分:1)

据我所知,Rx没有帮助编写功能。但是,这是你在寻找什么?



function a(source$) {
  return source$.map(x => x + '-first')
} 

function b(source$) {
  return source$.map(x => x + '-second')
} 

function c(source$) {
  return source$.map(x => x + '-third')
} 

const composed = R.compose(c, b, a);

composed(Rx.Observable.interval(1000))
  .subscribe(val => {
    console.log(val);
  });

<script src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.22.1/ramda.min.js"></script>
&#13;
&#13;
&#13;