bluebus

1.3.2 • Public • Published

bluebus

Build Status Coverage Status npm version Bower version GitHub version

Bluebus is a event library with bind/trigger system

Installation

NPM

npm install --save bluebus

You can found the library on node_modules/bluebus/dist/bluebus.js

Bower

bower install --save bluebus

You can found the library on bower_components/bluebus/dist/bluebus.js

Import

You can use Bluebus with require

var Bluebus = require('bluebus');

or as global variable, called Bluebus.

Usage

Simple use

// bind an event
Bluebus.bind('openMenu', function(number){
    console.log('value is ' + number);
});

// trigger an event
Bluebus.trigger('openMenu', 5);
// it executes previous binding on same event, console will logs 'value is 5'

Multiple bind

// bind an event
Bluebus.bind('color', function(number){
    console.log('yellow is ' + number);
});

// bind same event
Bluebus.bind('color', function(number){
    console.log('red is ' + number);
});

// trigger an event
Bluebus.trigger('color', 10);
// it executes previous binding functions
// console will logs 'yellow is 10' and 'red is 10'

Before trigger, after bind

// trigger an event before binding
Bluebus.trigger('closeMenu', 15);

// bind triggered event 
Bluebus.bind('closeMenu', function(number){
    console.log('new value is ' + number);
});
// it is immediately executed because this event has already been triggered
// console will logs 'new value is 15'

Multiple trigger

// bind an event
Bluebus.bind('multipleEvent', function(number){
    console.log('multipleEvent is ' + number);
});

// trigger an event 2 times, leaving stack
Bluebus.trigger('multipleEvent', 1, true);
Bluebus.trigger('multipleEvent', 2, true);
// Passing true as last parameter, the stack of binding functions is mantained
// console will logs 'multipleEvent is 1' and 'multipleEvent is 2'

Bluebus.trigger('multipleEvent', 3);
// If you don't pass true as last parameter, the stack of binding functions is cleaned
// console will logs 'multipleEvent is 3'

Bluebus.trigger('multipleEvent', 4);
// nothing is happening, the stack of binding functions is already cleaned

isTriggered

// check if an event has been triggered, returns true or false
Bluebus.isTriggered('openMenu');

clean and cleanAll

// clean a previous events and relative bindings
Bluebus.clean('openMenu');

// clean all events and relative bindings
Bluebus.cleanAll();

Contribute

To contribute to this library, read CONTRIBUTE.md

Package Sidebar

Install

npm i bluebus

Weekly Downloads

8

Version

1.3.2

License

MIT

Unpacked Size

7.05 MB

Total Files

147

Last publish

Collaborators

  • aureliome