Skip to content

Tiny signals implementation, Postal.js semi-compatible.

Notifications You must be signed in to change notification settings

sanyabeast/postal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postal

Channel/topic scheme

Subscribing

var subscription = postal.subscribe({
  channel : "kek",
  topic : "lol",
  callback : function(data){
    console.log("Hello!", data);
  },
  context : window
});

Publishing

postal.publish({
  channel : "kek",
  topic : "lol",
  data : "Goodbye!"
});

//Hello!, Goodbye!

Unsubscribing

subscription.unsubscribe();

Resubscribing

subscription.resubscribe();

Signals scheme

Listening

var subscription = postal.listen("logdata", function(data){
  console.log(data);
});

Saying

postal.say("logdata", { random : Math.random() });
//{random : 0.2943779978464365 }

Emitter scheme

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`

About

Tiny signals implementation, Postal.js semi-compatible.

Resources

Stars

Watchers

Forks

Packages

No packages published