info-bus
It can be used to communicate in any project.
get start
npm install info-bus --save
api
$on
Listen for an event
{ console}infoBus;
$emit
Triggering event
var information = 'Hello info-bus!';infoBus;// => Hello info-bus! // And you can trigger multiple callbacks in the same event as long as you have multiple listeners.{ console}infoBus; infoBus;// => Hello info-bus!// => Hello info-bus! this is callBack2.
$off
Log off events It can write off a callback for an event and also write off all callbacks.
// Cancels a callback for an event.infoBus; // Only Cancels the callBack1. // Cancels all callbacks for an event.infoBus;
$once
Triggered only once
infoBus; // It will only be triggered once. infoBus; // First emit.infoBus; // again. // => 'First_val1', 'First_val2'
usage
- es6
; // Mount to the global and use the same infobus anywhere.windowinfoBus = infoBus; { console;} { console;} // Listen for an eventinfoBus;infoBus;// Triggering eventinfoBus;// The console will print:// log1:123// log2:123 // Log off an eventinfoBus;// Only Cancels the log1.// Triggering eventinfoBus;// The console will print:// log2:123
- usual