JSFiddle - React, Tailwind, and code Playground

by chodorowicz

HTML

<script src="http://taylormcgann.com/play/q-1.js"></script>
<div id="console-log"></div>

JavaScript

var logContainer = document.getElementById('console-log');
 
console = {
    log: function (text) {
        var el = document.createElement("p");
    	el.innerHTML = text;
	    logContainer.appendChild(el);
    }
};

function fetchData() {
    return Q([1, 2, 3]);
}

function handleData() {
    return fetchData()
        .then(function (data) {
            console.log('handling ' + data);
            return data.reduce(function (memo, val) { return memo + val; });
        }, function (error) {
            console.error('handle error: ' + error.stack);
            throw error;
        })
}
 
function useData() {
    console.log('start');
    return handleData()
        .then(function (result) {
            console.log('using ' + result);
        }, function (error) {
            console.error('use error: ' + error.stack);
        })
        .fin(function () {
            console.log('finish');
        });
}
 
useData();