This lesson'll show when to apply groupBy in the real world. This RxJS operator was best suited when a source observable represents many data sources, e.g. an observable for multitouch Events.
ConstBusobservable =Rx.Observable.of ({code:'en -US', Value:'-test-'}, {code:'en -US', Value:'Hello'}, {code:'es', Value:'-test-'}, {code:'en -US', Value:'Amazing'}, {code:'PT-BR', Value:'-test-'}, {code:'PT-BR', Value:'Olá'}, {code:'es', Value:'Hola'}, {code:'es', Value:'Mundo'}, {code:'en -US', Value:' World'}, {code:'PT-BR', Value:'Mundo'}, {code:'es', Value:'Asombroso'}, {code:'PT-BR', Value:'Maravilhoso'}). concatmap (x= Rx.Observable.of (x). Delay ( -));Constall =busobservable. GroupBy (obj= Obj.code)//2-d Obs. Mergemap (Innerobs = Innerobs.skip (1). Map (obj =obj.value)); All.subscribe (x= Console.log (x));
/* "Hello" "Amazing" "Olá" "Hola" "Mundo" "World" "Mundo" "Asombroso" "Maravilhoso " */
- The ' groupBy ' return a 2-d observable, can use ' switchmap ' or ' mergemap ' to Conver to 1-d observable.
[RxJS] Use GroupBy in real RxJS applications