2016-06-26 1 views
1

出力を.groupByと.concatAllの組み合わせでグループ化すると、期待される出力が生成されません。RxJS groupByとcombineAll演算子が出力を省略しているように見える

サンプルコード:

var Rx = require('rx'); 

var source = Rx.Observable.from(['a1', 'a2', 'b1', 'b2', 'a3', 'a4', 'b3', 'b4']) 
    .groupBy(function (item) { return item.substr(0, 1); }) 
    .concatAll(); 

var subscription = source.subscribe(
    function (x) { 
    console.log('Next: %s', x); 
    }, 
    function (err) { 
    console.log('Error: %s', err); 
    }, 
    function() { 
    console.log('Completed'); 
    }); 

実際の出力:

$ node index.js 
Next: a1 
Next: a2 
Next: a3 
Next: a4 
Completed 

予想される出力:私はこれらの演算子がどのように機能するか

$ node index.js 
Next: a1 
Next: a2 
Next: a3 
Next: a4 
Next: b1 
Next: b2 
Next: b3 
Next: b4 
Completed 

誤解だろうか?またはこれはRxJSのバグですか? (すでにhttps://github.com/Reactive-Extensions/RxJS/issues/1264に一時的に提出されています)

答えて

1

それを実証しました。これはhot vs cold observablesの問題です。次のようにコードを変更すると、正常に動作します。

var source = Rx.Observable.from(['a1', 'a2', 'b1', 'b2', 'a3', 'a4', 'b3', 'b4']) 
    .groupBy(function (item) { return item.substr(0, 1); }) 
    .map(function (obs) { // <<<<< ADD THIS .map clause to fix 
    var result = obs.replay(); 
    result.connect(); 
    return result; 
    }) 
    .concatAll(); 
関連する問題