Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.48k stars 2.1k forks source link

toArray after groupBy not working ? #1070

Open vekexasia opened 8 years ago

vekexasia commented 8 years ago

Hello there,

i'm trying to sort the grouped observable by its key so that the groups are emitted using my ordering. But I found that writing .toArray().flatMap(Rx.Observable.from) (which in my knowledge should be one the inverse of the other) disrupts the groupedobservables somehow.

In the following snippet all the commented lines are non-working.

const a = [

  {a:2, b:'d'},
  {a:2, b:'e'},
  {a:3, b:'f'},
    {a:1, b:'b'},
  {a:1, b:'c'},
];

Rx.Observable.from(a)
  .groupBy(i=>i.a)
  //.toArray().doOnNext(groups => groups.sort((a,b)=>a.key-b.key)).flatMap(Rx.Observable.from)
  //.toArray().flatMap(Rx.Observable.from)
  .flatMap(group => group.map(item => ({item, key:group.key})))
  .subscribe(console.log)

What I want to accomplish is to get items with a=1 first then a=2 folllowed by the item having a=3.

By introducing one of the two commented lines no items are "console.logged"

vekexasia commented 8 years ago

Not sure if this might help but here is a jsbin https://jsbin.com/xolomikoso/edit?js,console