https://github.com/fabioricali/flak
JavaScript event emitter for browser and server.
https://github.com/fabioricali/flak
eventemitter events javascript-event-emitter listener nodejs
Last synced: 4 months ago
JSON representation
JavaScript event emitter for browser and server.
- Host: GitHub
- URL: https://github.com/fabioricali/flak
- Owner: fabioricali
- Created: 2017-08-07T07:19:15.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-23T11:29:26.000Z (almost 8 years ago)
- Last Synced: 2025-06-10T17:56:47.409Z (5 months ago)
- Topics: eventemitter, events, javascript-event-emitter, listener, nodejs
- Language: JavaScript
- Homepage:
- Size: 103 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
## Installation
### Node.js
```
npm install flak --save
```
## Example
```javascript
const Flak = require('flak');
const emitter = new Flak();
// Adds listener for the event
emitter.on('myEvent1', (param1, param2)=>{
console.log(param1, param2);
});
// Adds a one time listener function for the event
emitter.once('myEvent2', (param1, param2)=>{
console.log(param1, param2);
});
// Adds listener for the event that can be call just 4 time
emitter.on('myEvent3', (param1, param2)=>{
console.log(param1, param2);
}, {
maxCalls: 4
});
// Adds the listener function to the beginning of the listeners array for the event named myEvent1
emitter.on('myEvent1', (param1, param2)=>{
console.log(param1, param2);
}, {
prepend: true
});
// Catch all events
emitter.onCatchAll(params=>{
console.log(params);
});
// Fire event
emitter.fire('myEvent1', true, {a: 1});
// Fire async method
emitter.fireAsync('myEvent2', true, {a: 1});
// Remove all listeners for myEvent1
emitter.off('myEvent1');
// Returning data using "fireTheFirst"
emitter.on('myEvent', (param1, param2)=>{
return param1 + '-' + param2;
});
console.log('foo-bar' === emitter.fireTheFirst('myEvent', 'foo', 'bar')) //=> true;
// Suspend event
emitter.suspendEvent('myEvent');
emitter.fire('myEvent'); // will not be fired!
// Resume event
emitter.resumeEvent('myEvent');
```
### API Documentation
See full documentation here
### Browser
#### Local
```html
```
#### CDN unpkg
```html
```
#### CDN jsDeliver
```html
```
## Changelog
You can view the changelog here
## License
Flak is open-sourced software licensed under the MIT license
## Author
Fabio Ricali