JSFiddle - React, Tailwind, and code Playground

by gutek

HTML

<button id="run">POST EVENT</button>

JavaScript

(function () {

    /*
    fromStream("products")
       .when({
            $init: function() {
               return { count: 0 };
            },
            "Purchase": function(state, event) {
              state.count += 1;
            }
      });
    */
    
    function guid() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
    return v.toString(16);
});
    }
    
    $('#run').click(function () {
    
        var evt = {
            eventId: guid(),
            eventType: 'Purchase',
            data: {
                product: 'whatever' + guid(),
            }
        };
        
        $.ajax({
            type: 'POST',
            contentType: 'application/json',
            url: 'http://127.0.0.1:2113/streams/products',
            data: JSON.stringify([evt]),
            success: function () { alert('ok'); },
            error: function (z, s, err) { 
                alert(err);
            }
        });
        
    });

})();