Created
June 30, 2017 16:45
-
-
Save ivan-krukov/ed7d050a1f1033bd38555ce479fe871e to your computer and use it in GitHub Desktop.
Elementary observables // source https://jsbin.com/xekubas
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"> | |
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> |
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
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