Created
May 2, 2017 14:14
-
-
Save olimungo/411b8e06c4054e7eb42c09568d769b7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from './node_modules/rxjs/Rx'; | |
const list = [ | |
{ id: 1, name: 'Oli', type: 0 }, | |
{ id: 2, name: 'Pedro', type: 1 }, | |
{ id: 3, name: 'Rui', type: 1 }, | |
{ id: 4, name: 'Ainara', type: 2 } | |
]; | |
const types = [ | |
{ label: 'ALPHA' }, | |
{ label: 'BETA' }, | |
{ label: 'DELTA' } | |
]; | |
list$() | |
.switchMap(list => Observable.from(list)) | |
.concatMap(item => { | |
return type$(item.type) | |
.map(type => { | |
return { id: item.id, name: item.name, type: type.label }; | |
}); | |
}) | |
.subscribe(res => console.log(res)); | |
function list$(): Observable<any[]> { | |
return Observable.of(list); | |
} | |
function type$(id: number): Observable<any> { | |
return Observable.of(types[id]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment