JSFiddle - React, Tailwind, and code Playground

by gianlucaguarini

HTML

<div>
foo
</div>

JavaScript

var stroxy = (function () {
  'use strict';

  const ADD = 1;
  const REMOVE = -1;

  const createEmpty = obj => Object.assign(Object.create(null), obj);

  /**
   * The list of shorthand aliases for functions
   */
  const aliasRegistry = createEmpty({
    add: 'addEventListener',
    remove: 'removeEventListener',
  });

  /**
   * The list of streamable properties with their corresponding callback index
   */
  const streamableRegistry = createEmpty({
    addEventListener: {
      callbackIndex: 1,
      type: ADD,
    },
    removeEventListener: {
      callbackIndex: 1,
      type: REMOVE,
    },
    setTimeout: {
      callbackIndex: 0,
      type: ADD,
    },
    clearTimeout: {
      callbackIndex: 0,
      type: REMOVE,
    },
    setInterval: {
      callbackIndex: 0,
      type: ADD,
    },
    clearInterval: {
      callbackIndex: 0,
      type: REMOVE,
    },
    on: { // jQuery, EventEmitter
      callbackIndex: 1,
      type: ADD,
    }, // jQuery
    off: {
      callbackIndex: 1,
      type: REMOVE,
    }, // EventEmitter
    removeListener: {
      callbackIndex: 1,
      type: REMOVE,
    },
  });

  const getAlias = alias => aliasRegistry[alias] ? aliasRegistry[alias] : alias;
  const addAlias = (alias, name) => !aliasRegistry[alias] ? aliasRegistry[alias] = name : false;

  const isStreamable = name => !!streamableRegistry[name];
  const addStreamable = (name, config) => !streamableRegistry[name] ? streamableRegistry[name] = config : false;

  const objectRegex = /^\[object/;
  const isObject = obj => objectRegex.test(Object.prototype.toString.call(obj));
  const isNumber = number => number === Number(number);
  const isNodeList = obj => typeof NodeList !== 'undefined' ? NodeList.prototype.isPrototypeOf(obj) : false;

  /**
   * Run an array of stream instances
   * Should only be called from child instances (with pipes)
   * @param {Array} instances - The list of instances
   * @param {*} value - The current value of the parent
   */
 ...