A simple event library for Javascript
npm i emit-events --save
yarn add emit-events
import Events from 'emit-events';
// emit
Events.emit('myEvent', { foo: 'bar' });
// subscribe
Events.subscribe('myEvent', payload => {
// do something
});
import { emit, subscribe } from 'emit-events';
@subscribe('onEvent')
@emit()
class Foo {
onEvent(payload) {
console.log(payload);
}
sendIt() {
this.emit('onEvent', { foo: 'bar' });
}
}
import { emit, subscribe } from 'emit-events';
@subscribe(['onEvent', 'onEventAgain'])
@emit()
class Foo {
onEvent(payload) {
console.log(payload);
}
onEventAgain(payload) {
console.log(payload);
}
sendIt() {
this.emit('onEvent', { foo: 'bar' });
}
}