JSFiddle - React, Tailwind, and code Playground

by javajosh

HTML

<h1>Recursive version</h1>
<p>A set board is a list of ~7 bit numbers (to encode a number up to 81), usually about 12-15 numbers long. 84 bits in hex is 21 characters.</p>

<button class="start">start</button><br>
<button class="stop">stop</button><br>
<button class="add">add</button><br>

<pre class="state"></pre>

JavaScript

//var state = {i: 0, timerID: null};
function app(state, command){
    
    function add(){
        state.i++;
        display();
    }
    function display(){
        $('.state').text(JSON.stringify(state, null, 2))
    }
    this.start = function (){
        state.timerID = setInterval(function(){
            add();
        });
        display();
    };
    this.stop = function(){
        if (state.timerID) {
            clearInterval(state.timerID);
            state.timerID = null;
        }
        display();
    };
    this[command](state);
    console.log('app', arguments);
    return state;
}

//if only i could easily curry a function i wouldn't need these throw-away functios

$('button').click(function($e){
    debugger;
    app($e.target.className);
});

//$('.start').click();
//$('.stop').click(stop);
//$('.add').click(add);