JSFiddle - React, Tailwind, and code Playground

by rich_harris

HTML

<script src="http://cdn.ractivejs.org/edge/ractive.js"></script>
<main></main>

<script id='template' type='text/ractive'>
    <h2>Numbers</h2>
    <p>{{numbers}}</p>
    
    <h2>Sorted numbers</h2>
    <p>{{sort(numbers)}}</p>
    
    <h2>Unique numbers</h2>
    <p>{{_.uniq(numbers)}}</p>
    
    <button on-click='randomise'>randomise</button>
</script>

CSS

body {
    font-family: 'Helvetica Neue', arial, sans-serif;
    font-weight: 200;
    color: #353535;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 200;
}

JavaScript

// Ractive.defaults is an alias for Ractive.prototype
var helpers = Ractive.defaults.data;

helpers.sort = function ( array ) {
    return array.slice().sort( function ( a, b ) {
        return a - b;
    });
};

helpers._ = _; // lodash

var ractive = new Ractive({
    el: 'main',
    template: '#template',
    data: {
        numbers: [ 7, 8, 5, 9, 4, 2, 5, 2, 1, 9, 4, 4, 6 ]
    }
});

ractive.on( 'randomise', randomise );

function randomise () {
    var length, array = [], i;
    
    length = 5 + Math.round( Math.random() * 10 );
    
    for ( i = 0; i < length; i += 1 ) {
        array[i] = Math.round( Math.random() * 10 );
    }
    
    ractive.reset({ numbers: array});
}