Skip to content

Instantly share code, notes, and snippets.

@maxhoffmann
Created December 7, 2016 16:48
Show Gist options
  • Save maxhoffmann/c2f5e7b3eceeb28ba29708e022036111 to your computer and use it in GitHub Desktop.
Save maxhoffmann/c2f5e7b3eceeb28ba29708e022036111 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>
function clicks(broadcast) {
window.addEventListener('click', event => {
broadcast('click', event);
});
return () => {};
}
const services = [() => console.log, clicks];
buzz(services);
function buzz(services) {
const _bus = [];
const _services = [];
setupServices(broadcast);
requestAnimationFrame(run);
function broadcast(type, data) {
_bus.push({ type, data });
}
function setupServices(broadcast) {
for (const service of services) {
_services.push(service(broadcast))
}
}
function run(time) {
requestAnimationFrame(run);
for (const message of _bus.splice(0, 100)) {
for (const service of _services) {
service(message);
}
}
}
}
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"babel-runtime": "6.18.0"
}
}
'use strict';
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function clicks(broadcast) {
window.addEventListener('click', function (event) {
broadcast('click', event);
});
return function () {};
}
var services = [function () {
return console.log;
}, clicks];
buzz(services);
function buzz(services) {
var _bus = [];
var _services = [];
setupServices(broadcast);
requestAnimationFrame(run);
function broadcast(type, data) {
_bus.push({ type: type, data: data });
}
function setupServices(broadcast) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)(services), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var service = _step.value;
_services.push(service(broadcast));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
function run(time) {
requestAnimationFrame(run);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = (0, _getIterator3.default)(_bus.splice(0, 100)), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var message = _step2.value;
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = (0, _getIterator3.default)(_services), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var service = _step3.value;
service(message);
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment