Skip to content

Instantly share code, notes, and snippets.

/index.html
Created Jun 30, 2017

Embed
What would you like to do?
Elementary observables // source https://jsbin.com/muhitizuze
<!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">
'use strict';
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">let Observable = Rx.Observable
let errorButton = document.getElementById('error')
let errorClicks = Observable.fromEvent(errorButton, 'click')
errorClicks.forEach(
onNext = (x) => {
console.log('clicked')
throw('ERROR')
}
).then(
() => console.log('complete'),
(e) => console.log('error', e)
)
let button = document.getElementById('button')
let clicks = Observable.fromEvent(button, 'click')
let points =
clicks.map((e) => ({
x: e.clientX, y: e.clientY
}))
points.forEach((point) => {
console.log(point)
}
)
</script></body>
</html>
'use strict';
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.