Last active
September 9, 2018 21:06
-
-
Save sebabouche/bc4d280f828f2d68a8f516e064917f7e to your computer and use it in GitHub Desktop.
An RxJS 6 (6.2.1) bin / sandbox / playground
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="An RxJS 6.2.1 bin"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<button id="button">A button</button> | |
<script src="https://unpkg.com/@reactivex/rxjs@6.2.1/dist/global/rxjs.umd.js"></script> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
var _rxjs = rxjs; | |
var empty = _rxjs.empty; | |
var of = _rxjs.of; | |
var throwError = _rxjs.throwError; | |
var _rxjs$operators = rxjs.operators; | |
var catchError = _rxjs$operators.catchError; | |
var switchMap = _rxjs$operators.switchMap; | |
var btn1$ = rxjs.fromEvent(document.getElementById('button'), 'click'); | |
function randomError() { | |
var p = arguments.length <= 0 || arguments[0] === undefined ? 0.5 : arguments[0]; | |
var retval = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; | |
return Math.random() < p ? throwError(new Error('random error')) : of(retval); | |
} | |
btn1$.pipe(switchMap(function () { | |
return randomError(0.3, 'event').pipe(catchError(function (err) { | |
return console.warn('caught') && empty(); | |
})); | |
})).subscribe(function (evt) { | |
return console.log(evt); | |
}, function (err) { | |
return console.error(err.message); | |
}, function () { | |
return console.log('finish'); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const { | |
empty, | |
of, | |
throwError, | |
} = rxjs; | |
const { | |
catchError, | |
switchMap, | |
} = rxjs.operators; | |
const btn1$ = rxjs.fromEvent(document.getElementById('button'), 'click'); | |
function randomError(p = 0.5, retval = null) { | |
return (Math.random() < p) ? | |
throwError(new Error('random error')) : | |
of(retval); | |
} | |
btn1$ | |
.pipe( | |
switchMap(() => randomError(0.3, 'event').pipe( | |
catchError(err => console.warn('caught') && empty()), | |
)), | |
) | |
.subscribe( | |
evt => console.log(evt), | |
err => console.error(err.message), | |
() => console.log('finish'), | |
) | |
;</script></body> | |
</html> |
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
'use strict'; | |
var _rxjs = rxjs; | |
var empty = _rxjs.empty; | |
var of = _rxjs.of; | |
var throwError = _rxjs.throwError; | |
var _rxjs$operators = rxjs.operators; | |
var catchError = _rxjs$operators.catchError; | |
var switchMap = _rxjs$operators.switchMap; | |
var btn1$ = rxjs.fromEvent(document.getElementById('button'), 'click'); | |
function randomError() { | |
var p = arguments.length <= 0 || arguments[0] === undefined ? 0.5 : arguments[0]; | |
var retval = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; | |
return Math.random() < p ? throwError(new Error('random error')) : of(retval); | |
} | |
btn1$.pipe(switchMap(function () { | |
return randomError(0.3, 'event').pipe(catchError(function (err) { | |
return console.warn('caught') && empty(); | |
})); | |
})).subscribe(function (evt) { | |
return console.log(evt); | |
}, function (err) { | |
return console.error(err.message); | |
}, function () { | |
return console.log('finish'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment