https://github.com/kylecorry31/eventbusjs
https://github.com/kylecorry31/eventbusjs
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kylecorry31/eventbusjs
- Owner: kylecorry31
- License: mit
- Created: 2018-04-22T12:41:51.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-22T22:59:25.000Z (about 8 years ago)
- Last Synced: 2025-06-30T19:04:23.260Z (12 months ago)
- Language: JavaScript
- Size: 59.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Event Bus JS
A simple event bus framework for JavaScript.
## Installation
Just add the event_bus.js file to your project and include it with:
```html
```
## Usage
The Event Bus framework only provides three methods to subscribe, publish, or unsubscribe from events.
### Subscribe
```javascript
EventBus.subscribe("testEvent", function(data){
// Do something with data
console.log(data);
});
```
### Publish
```javascript
EventBus.publish("testEvent", 3);
```
### Unsubscribe
```javascript
EventBus.unsubscribe("testEvent", function(data){});
```
### Example
```javascript
var square = function(number){
console.log(number * number);
};
EventBus.subscribe("numbers", console.log);
EventBus.subscribe("numbers", square);
EventBus.publish("numbers", 1);
EventBus.publish("numbers", 2);
EventBus.unsubscribe("numbers", square);
EventBus.publish("numbers", 3);
```