https://github.com/scarletsfiction/eventpine
A simple extendable event emitter class
https://github.com/scarletsfiction/eventpine
browser deno event event-emitter node-js
Last synced: about 2 months ago
JSON representation
A simple extendable event emitter class
- Host: GitHub
- URL: https://github.com/scarletsfiction/eventpine
- Owner: ScarletsFiction
- License: mit
- Created: 2020-09-10T23:08:27.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-02T08:14:14.000Z (over 4 years ago)
- Last Synced: 2025-04-02T16:16:12.824Z (about 2 months ago)
- Topics: browser, deno, event, event-emitter, node-js
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
[](LICENSE)
[](https://www.jsdelivr.com/package/npm/eventpine)
[](https://twitter.com/intent/tweet?text=EventPine%20is%20a%20simple%20extendable%20event%20emitter%20class&url=https://github.com/ScarletsFiction/EventPine&via=github&hashtags=eventpine,browser,node,deno)# EventPine
A simple extendable event emitter class for Deno, Node, and Browser.### Getting Started
Before we start to use EventPine we need to import it first.#### Deno
Put this on your first line
```js
import 'https://x.nest.land/[email protected]/mod.js';
```#### Node
Add the module using package manager
```sh
$ npm i eventpine
```Then import it to your script
```js
let EventPine = require('eventpine');
```#### Browser
Put this on HTML ``
```xml```
### How to use
EventPine can be extended with your custom class.```js
// Custom class with EventPine (Optional)
class MyCustom extends EventPine{/* ... */}
var obj = new MyCustom();// Or just create from the root
var obj = new EventPine();// The next section also use this 'obj'
```### On
Listen to an event.```js
obj.on('message' /* EventName */, function(data1, data2){
// Do something
});
```### Once
Listen to an event then remove it after being called.```js
obj.once('message' /* EventName */, function(data1, data2){
// Do something once
});
```### Off
Remove event listener registered by on/once.```js
// Remove specific callback listener to this event
obj.off('message', myFunction);// Remove all event listener to this event name
obj.off('message');// Clear all event including the internal event
obj.off();
```If the second argument was empty, every callback related to this EventName will be removed.
### Emit
Emit to events that was registered.```js
obj.emit('message' /* EventName */, 'data1', 'data2', ...);
```## Internal Event
There are some internal event that may be useful.|EventName|Arguments|Description|
|---|---|---|
|`*`|EventName, ...|Wildcards event, everytime `emit` was called|```js
obj.on('*', function(...){
// Do stuff
});
```Instead of wildcard there are another experimental internal event, they're not documented yet because may be changed on the future.
## Contribution
If you want to help in EventPine please fork this project and edit on your repository, then make a pull request to here. Otherwise, you can help with donation via [patreon](https://www.patreon.com/stefansarya).But don't forget to put a link to this repository, or share it maybe.
## License
EventPine is under the MIT license.