JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cdn.ractivejs.org/edge/ractive.js"></script>
<p>Check the console!</p>
<main></main>
<script id='template' type='text/ractive'>
<ticker/>
</script>
CSS
body {
font-family: 'Helvetica Neue', arial, sans-serif;
font-weight: 200;
color: #353535;
}
h1, h2, h3, h4, h5, h6 {
font-weight: 200;
}
p {
margin: 0;
}
JavaScript
Ractive.components.ticker = Ractive.extend({
template: '<p>{{#if tick}}tick{{else}}tock{{/if}}</p>',
css: 'p { font-size: 4em; }',
init: function () {
var self = this;
setInterval( function () {
self.toggle( 'tick' );
}, 1000 );
this.observe( 'tick', function ( tick ) {
this.fire( tick ? 'tick' : 'tock' );
});
},
data: { tick: true }
});
var ractive = new Ractive({
el: 'main',
template: '#template'
});
ractive.on({
'ticker.tick': function () {
console.log( '%cticking...', 'color: green' );
},
'ticker.tock': function () {
console.log( '%ctocking...', 'color: purple' );
}
});