made with esnextbin
Last active
August 17, 2016 03:41
-
-
Save arecvlohe/c97122ef3a01331f350c8c2a954d3111 to your computer and use it in GitHub Desktop.
esnextbin sketch
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"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
</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
import Rx from 'rxjs/Rx'; | |
const buttonStart = document.createElement('button') | |
buttonStart.textContent = 'Add' | |
document.body.appendChild(buttonStart) | |
const buttonStop = document.createElement('button') | |
buttonStop.textContent = 'Subtract' | |
document.body.appendChild(buttonStop) | |
const time = document.createElement('p') | |
time.textContent = 0 | |
document.body.appendChild(time) | |
const start_ = Rx.Observable.fromEvent(buttonStart, 'click').mapTo(1) | |
const stop_ = Rx.Observable.fromEvent(buttonStop, 'click').mapTo(-1) | |
const combine_ = Rx.Observable | |
.merge(start_, stop_) | |
.scan((a, c) => a + c) | |
combine_.subscribe(x => { | |
time.textContent = `${x}` | |
}) |
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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"rxjs": "5.0.0-beta.11" | |
} | |
} |
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 _Rx = require('rxjs/Rx'); | |
var _Rx2 = _interopRequireDefault(_Rx); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var buttonStart = document.createElement('button'); | |
buttonStart.textContent = 'Add'; | |
document.body.appendChild(buttonStart); | |
var buttonStop = document.createElement('button'); | |
buttonStop.textContent = 'Subtract'; | |
document.body.appendChild(buttonStop); | |
var time = document.createElement('p'); | |
time.textContent = 0; | |
document.body.appendChild(time); | |
var start_ = _Rx2.default.Observable.fromEvent(buttonStart, 'click').mapTo(1); | |
var stop_ = _Rx2.default.Observable.fromEvent(buttonStop, 'click').mapTo(-1); | |
var combine_ = _Rx2.default.Observable.merge(start_, stop_).scan(function (a, c) { | |
return a + c; | |
}); | |
combine_.subscribe(function (x) { | |
time.textContent = '' + x; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment