https://github.com/d-mobilelab/bluebus
Event Emitter with advanced bind/trigger system
https://github.com/d-mobilelab/bluebus
bind bower event-emitter event-management eventbus trigger-events
Last synced: 11 months ago
JSON representation
Event Emitter with advanced bind/trigger system
- Host: GitHub
- URL: https://github.com/d-mobilelab/bluebus
- Owner: D-Mobilelab
- Created: 2017-03-02T11:37:07.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-07-25T14:30:42.000Z (almost 7 years ago)
- Last Synced: 2025-06-30T06:41:09.672Z (12 months ago)
- Topics: bind, bower, event-emitter, event-management, eventbus, trigger-events
- Language: JavaScript
- Homepage:
- Size: 508 KB
- Stars: 0
- Watchers: 6
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# bluebus
[](https://travis-ci.org/D-Mobilelab/bluebus)
[](https://coveralls.io/github/D-Mobilelab/bluebus?branch=master)
[](https://badge.fury.io/js/bluebus)
[](https://badge.fury.io/bo/bluebus)
[](https://badge.fury.io/gh/D-Mobilelab%2Fbluebus)
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