Bullet pub-sub Library

Bullet is an ultra lightweight and simple to use pub-sub library with zero dependencies, AMD/module support and an intuitive API.
It was built to facilitate a simple and consistent system of communication across web applications and includes only the bare essentials typically needed to achieve this.

.once()

This function behaves in the same way as the the 'on' function, except that – once registered – the callback function will only be called a single time when the specified message is triggered.

Example usage:

function helloCallback () {
console.log("hello there :)");
}
// Register the 'helloCallback' function to be called whenever the 'hello' message is triggered:
Bullet.once("hello", helloCallback);
// Somewhere later in the application...
// Trigger the 'hello' message – Bullet will call the 'helloCallback' function:
Bullet.trigger("hello");
// Attempt to trigger the 'hello' message again – Bullet won't call any functions this time:
Bullet.trigger("hello");

.trigger()

Bullet.trigger("someMessageName"[, data]);

This function will call all callback functions registered against the specified message, optionally passing in custom data as a payload.

Example usage:

function helloCallback () {
console.log("hello there :)");
}
// Register the 'helloCallback' function to be called whenever the 'hello' message is triggered:
Bullet.on("hello", helloCallback);
// Somewhere later in the application...
// Trigger the 'hello' message – Bullet will call the 'helloCallback' function:
Bullet.trigger("hello");

Example usage with custom data:

function userAddedCallback (data) {
console.log(data);
}
// Register the 'userAddedCallback' function to be called whenever the 'user-added' message is triggered:
Bullet.on("user-added", userAddedCallback);
// Somewhere later in the application...
// Create some custom data:
var customData = {
someProp : "bro",
someOtherProp : "awesome!"
};
// Trigger the 'user-added' message – Bullet will call the 'helloCallback' function and
// pass in the custom data that you created, which will be sent to the function as a parameter:
Bullet.trigger("user-added", customData);