Skip to content

Instantly share code, notes, and snippets.

@arecvlohe
Last active August 17, 2016 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arecvlohe/c97122ef3a01331f350c8c2a954d3111 to your computer and use it in GitHub Desktop.
Save arecvlohe/c97122ef3a01331f350c8c2a954d3111 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!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>
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}`
})
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"rxjs": "5.0.0-beta.11"
}
}
'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