Created
June 30, 2017 16:42
-
-
Save anonymous/7fd10927e5e33ff0eb51ab44e57c209a to your computer and use it in GitHub Desktop.
Elementary observables // source https://jsbin.com/muhitizuze
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 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"> | |
'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> |
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 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