Skip to content

Instantly share code, notes, and snippets.

@Ks89
Created September 25, 2018 20:39
Show Gist options
  • Save Ks89/836ed0324bf73977faee40be46e0ff1d to your computer and use it in GitHub Desktop.
Save Ks89/836ed0324bf73977faee40be46e0ff1d to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/yijesed
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script>
</head>
<body>
<script id="jsbin-javascript">
// Author Stefano Cappa (https://github.com/Ks89)
'use strict';
var letter$ = Rx.Observable.of('a');
var result$ = letter$.mergeMap(function (letter) {
return doSomethingWithLetter(letter);
}).mergeMap(function (response) {
return doSomethingWithNum(response[1]);
}).mergeMap(function (response) {
return doSomethingWithChar(response[1]);
});
result$.subscribe(function (x) {
return console.log(x[1]);
}, function (err) {
return console.log(err);
}, function () {
return console.log('Done');
});
// return the result of an async obs + the input param as an array of result
function doSomethingWithLetter(letter) {
console.log('use letter here', letter);
var syncObs$ = Rx.Observable.of(letter);
var asyncObs$ = Rx.Observable.of(letter + 1).delay(1000);
return syncObs$.combineLatest(asyncObs$, function (a, b) {
return [a, b];
});
}
// return the result of an async obs + the input param as an array of result
function doSomethingWithNum(num) {
console.log('use num here', num);
var syncObs$ = Rx.Observable.of(num);
var asyncObs$ = Rx.Observable.of(num + '_').delay(1000);
return syncObs$.combineLatest(asyncObs$, function (a, b) {
return [a, b];
});
}
// return the result of an async obs + the input param as an array of result
function doSomethingWithChar(char) {
console.log('use special char here', char);
var syncObs$ = Rx.Observable.of(char);
var asyncObs$ = Rx.Observable.of(char + 'qqqq').delay(1000);
return syncObs$.combineLatest(asyncObs$, function (a, b) {
return [a, b];
});
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">// Author Stefano Cappa (https://github.com/Ks89)
let letter$ = Rx.Observable.of('a');
let result$ = letter$
.mergeMap(letter => {
return doSomethingWithLetter(letter);
})
.mergeMap(response => {
return doSomethingWithNum(response[1]);
})
.mergeMap(response => {
return doSomethingWithChar(response[1]);
});
result$.subscribe(
x => console.log(x[1]),
err => console.log(err),
() => console.log('Done')
);
// return the result of an async obs + the input param as an array of result
function doSomethingWithLetter(letter) {
console.log('use letter here', letter)
let syncObs$ = Rx.Observable.of(letter);
let asyncObs$ = Rx.Observable.of(letter + 1).delay(1000);
return syncObs$.combineLatest(asyncObs$, (a,b) => [a, b]);
}
// return the result of an async obs + the input param as an array of result
function doSomethingWithNum(num) {
console.log('use num here', num)
let syncObs$ = Rx.Observable.of(num);
let asyncObs$ = Rx.Observable.of(num + '_').delay(1000);
return syncObs$.combineLatest(asyncObs$, (a,b) => [a, b]);
}
// return the result of an async obs + the input param as an array of result
function doSomethingWithChar(char) {
console.log('use special char here', char)
let syncObs$ = Rx.Observable.of(char);
let asyncObs$ = Rx.Observable.of(char + 'qqqq').delay(1000);
return syncObs$.combineLatest(asyncObs$, (a,b) => [a, b]);
}</script></body>
</html>
// Author Stefano Cappa (https://github.com/Ks89)
'use strict';
var letter$ = Rx.Observable.of('a');
var result$ = letter$.mergeMap(function (letter) {
return doSomethingWithLetter(letter);
}).mergeMap(function (response) {
return doSomethingWithNum(response[1]);
}).mergeMap(function (response) {
return doSomethingWithChar(response[1]);
});
result$.subscribe(function (x) {
return console.log(x[1]);
}, function (err) {
return console.log(err);
}, function () {
return console.log('Done');
});
// return the result of an async obs + the input param as an array of result
function doSomethingWithLetter(letter) {
console.log('use letter here', letter);
var syncObs$ = Rx.Observable.of(letter);
var asyncObs$ = Rx.Observable.of(letter + 1).delay(1000);
return syncObs$.combineLatest(asyncObs$, function (a, b) {
return [a, b];
});
}
// return the result of an async obs + the input param as an array of result
function doSomethingWithNum(num) {
console.log('use num here', num);
var syncObs$ = Rx.Observable.of(num);
var asyncObs$ = Rx.Observable.of(num + '_').delay(1000);
return syncObs$.combineLatest(asyncObs$, function (a, b) {
return [a, b];
});
}
// return the result of an async obs + the input param as an array of result
function doSomethingWithChar(char) {
console.log('use special char here', char);
var syncObs$ = Rx.Observable.of(char);
var asyncObs$ = Rx.Observable.of(char + 'qqqq').delay(1000);
return syncObs$.combineLatest(asyncObs$, function (a, b) {
return [a, b];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment