@mobilabs/messenger
v1.0.4
Published
A tiny Javascript library to handle messages that carry a payload
Downloads
7
Readme
Messenger
Messenger
is a tiny Javascript library to handle messages that carry a payload. It is designed to be embedded in another library. Messenger
run on both Node.js and ECMAScript 2015 (ES6) compliant browsers.
Quick Startup
// Listens for an event:
mess.subscribe('mycustomevent', function(payload) {
console.log('fired mycustomevent: ' + payload);
});
// Fires an event:
mess.publish('mycustomevent', 'this is the payload for mycustomevent');
API
Static methods
Messenger provides a set of static methods. You can use by typing:
Messenger.noConflict();
| Static Methods | Description | |:---------------------|:------------| | noConflict | returns the Messenger variable to its previous owner, |
Create a Messenger object:
| Constructor | Description | |:------------|:------------| | Messenger() | creates the Messenger object that handles messages, |
Methods
| Methods | Description | |:--------------------|:------------| | subscribe | adds an event listener, | | subscribeOnce | adds an event listener that is fired once, | | unsubscribe | removes an event listener, | | publish | fires an event/message, |
License
MIT.