Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Elementary observables // source https://jsbin.com/xekubas
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Elementary observables</title>
</head>
<body>
<script src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script>
<button id='error'>Will throw</button>
<button id='button'>Point</button>
<script id="jsbin-javascript">
var Observable = Rx.Observable;
var errorButton = document.getElementById('error');
var errorClicks = Observable.fromEvent(errorButton, 'click');
errorClicks.forEach(onNext = function (x) {
console.log('clicked');
throw 'ERROR';
}).then(function () {
return console.log('complete');
}, function (e) {
return console.log('error', e);
});
var button = document.getElementById('button');
var clicks = Observable.fromEvent(button, 'click');
var points = clicks.map(function (e) {
return {
x: e.clientX, y: e.clientY
};
});
points.forEach(function (point) {
console.log(point);
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">var Observable = Rx.Observable;
var errorButton = document.getElementById('error');
var errorClicks = Observable.fromEvent(errorButton, 'click');
errorClicks.forEach(onNext = function (x) {
console.log('clicked');
throw 'ERROR';
}).then(function () {
return console.log('complete');
}, function (e) {
return console.log('error', e);
});
var button = document.getElementById('button');
var clicks = Observable.fromEvent(button, 'click');
var points = clicks.map(function (e) {
return {
x: e.clientX, y: e.clientY
};
});
points.forEach(function (point) {
console.log(point);
});</script></body>
</html>
var Observable = Rx.Observable;
var errorButton = document.getElementById('error');
var errorClicks = Observable.fromEvent(errorButton, 'click');
errorClicks.forEach(onNext = function (x) {
console.log('clicked');
throw 'ERROR';
}).then(function () {
return console.log('complete');
}, function (e) {
return console.log('error', e);
});
var button = document.getElementById('button');
var clicks = Observable.fromEvent(button, 'click');
var points = clicks.map(function (e) {
return {
x: e.clientX, y: e.clientY
};
});
points.forEach(function (point) {
console.log(point);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.