Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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>
const inputs = [clicks];
const bus = [];
const services = [console.log];
function clicks(broadcast) {
window.addEventListener('click', event => {
broadcast('click', event);
});
}
buzz({
inputs,
bus,
services,
})
activateInputs(broadcast, inputs);
requestAnimationFrame(run);
function activateInputs(broadcast, inputs) {
for (const input of inputs) {
input(broadcast);
}
}
function broadcast(type, data) {
bus.push({ type, data });
}
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 }; }
var inputs = [clicks];
var bus = [];
var services = [console.log];
function clicks(broadcast) {
window.addEventListener('click', function (event) {
broadcast('click', event);
});
}
buzz({
inputs: inputs,
bus: bus,
services: services
});
activateInputs(broadcast, inputs);
requestAnimationFrame(run);
function activateInputs(broadcast, inputs) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)(inputs), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var input = _step.value;
input(broadcast);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
function broadcast(type, data) {
bus.push({ type: type, data: data });
}
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