Skip to content

Instantly share code, notes, and snippets.

@maxhoffmann
Created December 6, 2016 23:07
Show Gist options
  • Select an option

  • Save maxhoffmann/d01d09cbb99c04fc1d22cfdaebf6bced to your computer and use it in GitHub Desktop.

Select an option

Save maxhoffmann/d01d09cbb99c04fc1d22cfdaebf6bced to your computer and use it in GitHub Desktop.

Revisions

  1. Maximilian Hoffmann created this gist Dec 6, 2016.
    1 change: 1 addition & 0 deletions esnextbin.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    made with [esnextbin](http://esnextb.in)
    11 changes: 11 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <!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>
    38 changes: 38 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    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);
    }
    }
    }
    7 changes: 7 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    {
    "name": "esnextbin-sketch",
    "version": "0.0.0",
    "dependencies": {
    "babel-runtime": "6.18.0"
    }
    }
    108 changes: 108 additions & 0 deletions transpiled.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,108 @@
    '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;
    }
    }
    }
    }