JSFiddle - React, Tailwind, and code Playground

by ifandelse

HTML

<script src="https://rawgit.com/lodash/lodash/2.4.1/dist/lodash.underscore.js"></script>
<script src="https://rawgit.com/ifandelse/riveter/master/lib/riveter.js"></script>
<script src="https://rawgit.com/ifandelse/machina.js/master/lib/machina.js"></script>

JavaScript

/**
 * monologue.js - EventEmitter replacement with AMQP-style bindings and other advanced features. Compatible with postal.js's API.
 * Author: Jim Cowart (http://freshbrewedcode.com/jimcowart)
 * Version: v0.2.0
 * Url: https://github.com/postaljs/monologue.js
 * License(s): MIT, GPL
 */
(function (root, factory) {
    if (typeof module === "object" && module.exports) {
        // Node, or CommonJS-Like environments
        module.exports = factory(require("lodash"), require("riveter"));
    } else if (typeof define === "function" && define.amd) {
        // AMD. Register as an anonymous module.
        define(["lodash", "riveter"], function (_, riveter) {
            return factory(_, riveter, root);
        });
    } else {
        // Browser globals
        root.Monologue = factory(root._, root.riveter, root);
    }
}(this, function (_, riveter, global, undefined) {
    var bindingsResolver = {
        cache: {},
        regex: {},
        compare: function (binding, topic) {
            var pattern, rgx, prevSegment, result = (this.cache[topic] && this.cache[topic][binding]);
            if (typeof result !== "undefined") {
                return result;
            }
            if (!(rgx = this.regex[binding])) {
                pattern = "^" + _.map(binding.split("."), function (segment) {
                    var res = "";
                    if ( !! prevSegment) {
                        res = prevSegment !== "#" ? "\\.\\b" : "\\b";
                    }
                    if (segment === "#") {
                        res += "[\\s\\S]*";
                    } else if (segment === "*") {
                        res += "[^.]+";
                    } else {
                        res += segment;
                    }
                    prevSegment = segment;
                    return res;
                }).join("") + "$";
                rgx = this.regex[binding] = new RegExp(pattern);
            }
            this.cache[topic] = this.cache[topic]...