Try Out Amplify

by vbfischer

HTML

<script src="https://raw.github.com/appendto/amplify/master/core/amplify.core.js"></script>
<script src="https://raw.github.com/appendto/amplify/master/store/amplify.store.js"></script>
<script src="https://raw.github.com/appendto/amplify/master/request/amplify.request.js"></script>
<div id="helloDiv">hello</div>
<div id="helloDiv2">temp</div>

JavaScript

(function() {
    $.widget("ui.widget1", {
        options: {
            message: 'hello default'
        },
        _init: function() {
            console.log('init');
        },
        show: function(message) {
            amplify.publish("notify.someevent", {
                message: "From Widget 1!"
            });
        }
    });
    
    $.widget("ui.widget2", {
        _init: function() {
            amplify.subscribe("notify.someevent", this, function(data) {
                this.element.empty();
                this.element.append(data.message);
            }); 
        }
    });
    
}).call(this);
$("#helloDiv").widget1();
$("#helloDiv2").widget2();
$("#helloDiv").widget1("show", "hello there");