Skip to content

Instantly share code, notes, and snippets.

@sdesai
Last active August 29, 2015 14:10
Show Gist options
  • Save sdesai/e22a6376fc0769337b84 to your computer and use it in GitHub Desktop.
Save sdesai/e22a6376fc0769337b84 to your computer and use it in GitHub Desktop.
Nested switchMap Issue?
var Observable = Rx.Observable;
// Nested SwitchLatest/SwitchMap BROKEN?
// Expecting: "A", "B" (with synchronous scheduler/execution)
// Observed: "B"
Observable.of(
Observable.of('A').switchMap(function(o) {
return Observable.of(o);
}),
Observable.of('B')
).
switchLatest().
forEach(function(o){
console.log(o);
});
// Expecting: "A", "B" (with synchronous scheduler/execution)
// Observed: "B"
Observable.of(
Observable.of('A').switchMap(function(o) {
return Observable.of(o);
}),
Observable.of('B').switchMap(function(o) {
return Observable.of(o);
})
).
switchLatest().
forEach(function(o){
console.log(o);
});
// Expecting: "A", "B", "C" (with synchronous scheduler/execution)
// Observed: "C"
Observable.of(
Observable.of('A').switchMap(function(o) {
return Observable.of(o);
}),
Observable.of('B').switchMap(function(o) {
return Observable.of(o);
}),
Observable.of('C').switchMap(function(o) {
return Observable.of(o);
})
).
switchLatest().
forEach(function(o){
console.log(o);
});
// 'WORKING' VARIANTS
// Expecting: "B", "A"
// Observed: "B", "A"
Observable.of(
Observable.of('B'),
Observable.of('A').switchMap(function(o) {
return Observable.of(o);
})
).
switchLatest().
forEach(function(o){
console.log(o);
});
// Expecting: "A"
// Observed: "A"
Observable.of(
Observable.of('A').switchMap(function(o) {
return Observable.of(o);
})
).
switchLatest().
forEach(function(o){
console.log(o);
});
// Expecting: "A"
// Observed: "A"
Observable.of('A').switchMap(function(o) {
return Observable.of(o);
}).
forEach(function(o){
console.log(o);
});
// Expecting: Two Observables On Nexted
// Observed: Two Observables On Nexted
Observable.of(
Observable.of('A').switchMap(function(o) {
return Observable.of(o);
}),
Observable.of('B').switchMap(function(o) {
return Observable.of(o);
})
).
// switchLatest(). removed
forEach(function(o){
console.log(o);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment