JSFiddle - React, Tailwind, and code Playground

by kapuca

HTML

<script src="http://knockoutjs.com/downloads/knockout-3.2.0.js"></script>
<voting params="votes: votes"></voting>

<template id="voting-tpl">
    <button data-bind="click: increment ">Up</button>
    <div data-bind="text: votes"></div>
</template>

JavaScript

ko.components.register('voting', {
    viewModel: function(params) {
        var self        = this;
        self.votes      = params.votes;
        
        self.increment  = function(){
            self.votes( self.votes() + 1 );
        };
        
        return self;
    },
    template: { element: 'voting-tpl' }
});

function Vm(){
    this.votes = ko.observable(5);
    return this;
}

ko.applyBindings(new Vm() );