@kjojs/eventbus
v1.1.4
Published
universal and light(1kb) event bus module
Downloads
2
Maintainers
Readme
@kjojs/eventbus
- universal and light(1kb) event bus module
- no dependencies
- typescript type inference supports.
- simple and light implementation
Installation
npm install @kjojs/eventbus --save
Getting Started
import EventBus from '@kjojs/eventbus';
const eventBus = new EventBus();
eventBus.on('a', console.log);
eventBus.on({
b: console.log,
c: console.log,
});
eventBus.emit('a', 2);
eventBus.emit('b', 'p');
eventBus.emit('c', { n: 1 });
Type Inference Support
interface EventDefinition {
a: 1 | 2 | 3;
b: 'p';
}
const eventBus = new EventBus<EventDefinition>().on({
a: console.log,
b: console.log,
});
/**
* or
*
* new EventBus<{
* a: 1 | 2 | 3;
* b: 'p';
* }>();
*/
Specifications
- spec code
.on(eventName, eventHandler, life?)
.on(eventSpecification)
.once(eventName, eventHandler)
.once(eventSpecification)
.off()
.off(eventName)
.off(eventName, eventHandler)
.has()
.has(eventName)
.has(eventName, eventHandler)
.emit(eventName, eventPayload?)