Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pimdewit/event-dispatcher
Performant, opinionated event dispatcher.
https://github.com/pimdewit/event-dispatcher
eventdispatcher events typescript
Last synced: about 1 month ago
JSON representation
Performant, opinionated event dispatcher.
- Host: GitHub
- URL: https://github.com/pimdewit/event-dispatcher
- Owner: pimdewit
- License: mit
- Created: 2018-11-03T11:10:21.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2022-10-10T09:19:09.000Z (about 2 years ago)
- Last Synced: 2024-10-05T11:05:43.909Z (about 2 months ago)
- Topics: eventdispatcher, events, typescript
- Language: TypeScript
- Homepage:
- Size: 95.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EventDispatcher
Performant, opinionated event dispatcher.
## Installation
`npm install @pdw.io/event-dispatcher`
## Usage
Below is a very minimal example. The main thing to note is that the "event names" are strictly numbers (Enum keys in this case), this is where the performance comes from.
```typescript
import { EventDispatcher } from '@pdw.io/eventdispatcher';export enum DialogEventName {
OPEN,
CLOSE,
}class Dialog extends EventDispatcher {
private open = false;toggle() {
this.open = !this.open;
const eventToSend = this.open ? DialogEventName.OPEN : DialogEventName.CLOSE;
this.dispatchEvent(eventToSend);
}
}const dialog = new Dialog();
dialog.addEventListener(DialogEventName.OPEN, callback);
```