Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iminside/js.event_emitter
Event emitter for es6 classes
https://github.com/iminside/js.event_emitter
Last synced: 1 day ago
JSON representation
Event emitter for es6 classes
- Host: GitHub
- URL: https://github.com/iminside/js.event_emitter
- Owner: iminside
- Created: 2015-09-15T06:28:38.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-22T08:21:10.000Z (over 9 years ago)
- Last Synced: 2024-12-08T08:34:41.999Z (19 days ago)
- Language: JavaScript
- Homepage:
- Size: 137 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Install
```
npm install js.event_emitter --save
```### Usage
```javascript
import EventEmitter from "js.event_emitter";
class Cat extends EventEmitter {}
class Dog extends EventEmitter {
constructor(){
this.name = "Bob";
}gav(){
console.log( this.name + " gav" );
}manyGav(){
console.log( this.name + " gav gav gav" );
}}
let dog = new Dog,
cat = new Cat;
cat.on( // attach event handler, call on every trigger
"run", // event name
dog.gav, // event handler
dog // callback context
);cat.one( "run", dog.manyGav, dog ); // call on first trigger
cat.trigger( "run" ); // > "Bob gav"
// > "Bob gav gav gav"
cat.trigger( "run" ); // > "Bob gav"
cat.trigger( "run" ); // > "Bob gav"cat.off(); // detach all handlers of all events
cat.off( "run" ); // detach all handlers of "run" event
cat.off( "run", dog.gav ); // detach dog.gav handler of "run" event
cat.off( "run", dog.gav, dog ); // detach dog.gav handler of "run" event when context is dog```