var subscription = postal.subscribe({
channel : "kek",
topic : "lol",
callback : function(data){
console.log("Hello!", data);
},
context : window
});
postal.publish({
channel : "kek",
topic : "lol",
data : "Goodbye!"
});
//Hello!, Goodbye!
subscription.unsubscribe();
subscription.resubscribe();
var subscription = postal.listen("logdata", function(data){
console.log(data);
});
postal.say("logdata", { random : Math.random() });
//{random : 0.2943779978464365 }
class BlackBox {
constructor(){
this.emitter = new postal.Emitter(/*uid*/"blackbox");
}
addEventListener(eventname, cb cbcontext){
this.emitter.on(eventname, cb, cbcontext);
}
sayHello(){
console.log("hello!");
this.emitter.dispatch("hello");
}
}
var box = new BlackBox();
box.addEventListener("hello", function(){
console.log("blackbox just said `hello`");
});
box.sayHello();
//hello!
//blackbox just said `hello`