JSFiddle - React, Tailwind, and code Playground

by phsiao2000

HTML

<script src="http://localhost:3000/scripts/jsonpath-0.8.0.js"></script>
<script src="https://raw.github.com/lodash/lodash/2.4.1/dist/lodash.js"></script>
<!-- test jsonpath */ -->
<pre id='out'>data here</pre>

JavaScript

log('test');
document.getElementById('out').textContent = JSON.stringify({
    v: 34
});

function log(v) {
    document.getElementById('out').textContent = v;

}
Object.prototype.toJSONString = function () {
    return JSON.stringify(this, null, 5);
};
function query (d) {
    var qp = "$.[1].fragments[*].value";
    var jp = jsonPath(d, qp, {resultType:"PATH"});
    return _.uniq(jp);
}
var clear = false;
if(clear) {localStorage.removeItem("docs"); clear = false;}
if (localStorage && localStorage.getItem("docs")) {
    var z = JSON.parse(localStorage.getItem("docs"));
    //debugger;
    var p = query(z);
    log(p.toJSONString());

} else {
    var jqxhr = $.getJSON("http://localhost:3000/data/all", function (d) {
        console.log("success");
        localStorage.setItem("docs", d.toJSONString());
        var p = query(d);
        log(p.toJSONString());
    })
        .done(function () {
        console.log("second success");
    })
        .fail(function () {
        console.log("error");
    })
        .always(function () {
        console.log("complete");
    });
}