An event superclass for automatic method generation
npm install vento
npm install vento
`
Usage
First you have to import Vento to the file you want to use it.
`javascript
import Vento from 'vento';
`
Then extend your class with Vento.
`javascript
class MyClass extends Vento {}
`
After this you can register new events either in the constructor or somewhere else.
`javascript
this.addEvent('eventName');
`
You can also bind an internal method directly to your event.
`javascript
this.addEvent('eventName', this.eventName);
`
Then you can register to the event. You can create an internal on function or register from external to your event.
`javascript
eventName() {
// do something
}
or
myClass.on('eventName', () => {
// do something
});
or
myClass.onEventName(() => {
// do something
});
`
Thats it... now you can fire your custom created event.
`javascript
myClass.fireEventName();
or
myClass.fireEventName('some', { data: true });
`
$3
`javascript
import Vento from 'vento';
class MyClass extends Vento {
constructor() {
this.addEvent('test', this.test);
}
test(data1, data2) {
console.log('inner notification', data1, data2);
}
}
const myClass = new MyClass();
myClass.on('test', (data1, data2) => {
console.log('outter notification bound with on', data1, data2);
});
myClass.onTest((data1, data2) => {
console.log('outter notification bound with onTest', data1, data2);
});
myClass.fireOnTest('first object', 'second object');
`
Extend extended class
what? ...
If you have a class that already extends a class... or is extended by a class you should also have the ability to use Vento.
So you can just hook Vento in the constructor of your sub class.
`javascript
class SubClass extends SuperClass {
constructor() {
super();
Vento.extend(this);
this.addEvent('test');
}
}
``