Skip to content

Instantly share code, notes, and snippets.

@ivan-krukov
Created June 30, 2017 16:45
Show Gist options
  • Save ivan-krukov/ed7d050a1f1033bd38555ce479fe871e to your computer and use it in GitHub Desktop.
Save ivan-krukov/ed7d050a1f1033bd38555ce479fe871e to your computer and use it in GitHub Desktop.
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/[email protected]/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