JSFiddle - React, Tailwind, and code Playground

by Derek Anderson

HTML

<script src="https://dl.dropboxusercontent.com/u/10409166/yobidashi/build/yobidashi.min.js"></script>

JavaScript

//create a data object to bind to
var data = {foo:'bar'};

//create a callback, bind to the data
//yobidashi has a underscore's bind built in, 
//you can use your own if you want.
var cb = yobidashi.bind(function(){
    
    //simple call back, gets the foo property for this
    var foo = this.foo;
    //displays the value of foo property from local var
    document.getElementsByTagName("body")[0].innerHTML += 'foo:' + foo + '<br/>';
    
}, data);

//subscribe to some channel
yobidashi.sub('/channel', cb);

//publish to some channel
yobidashi.pub('/channel', {foo:'stuff'});

//change the data if you want
data.foo = 'wat';

//publish to some channel, if bound to the data object
//data in foo is different
yobidashi.pub('/channel');

//unsubscribe with reference to same callback
yobidashi.unsub('/channel', cb);

//publish to some channel, it wont fire off the cb again
yobidashi.pub('/channel');