Last active
July 18, 2017 04:50
-
-
Save Restuta/b658ee1b7eb2abf7751fc957cf5f5ef7 to your computer and use it in GitHub Desktop.
RxJS Switch Map
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
// Will and I tried to merge sorted observables with swithcMap, but we cound't | |
console.clear() | |
function main() { | |
// var observables = [ | |
// Rx.Observable.of([1,2,3]), | |
// Rx.Observable.of([2,4,5]), | |
// //Rx.Observable.of([1,7,9]) | |
// ] | |
var o1 = Rx.Observable.of(1,2,3) | |
var o2 = Rx.Observable.of(40,50,60) | |
function createSorter(){ | |
let mySortedList = [] | |
return (outerVal, innerVal) => { | |
mySortedList.push(outerVal) | |
mySortedList.push(innerVal) | |
console.log('sorter:') | |
console.log(outerVal, innerVal) | |
console.log(mySortedList) | |
mySortedList = mySortedList.sort() | |
return mySortedList.pop() | |
} | |
} | |
var result = o1.switchMap( | |
x => o1, | |
createSorter() | |
); | |
var subscr = result.subscribe(x => { | |
console.log(x) | |
}); | |
} | |
main() | |
// 01.mergeMap(o2).mergeMap(o3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment