Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hypernym-studio/emitter
A super simple and lightweight event emitter.
https://github.com/hypernym-studio/emitter
emit emitter event event-emitter events javascript-emitter typescript-emitter
Last synced: 2 days ago
JSON representation
A super simple and lightweight event emitter.
- Host: GitHub
- URL: https://github.com/hypernym-studio/emitter
- Owner: hypernym-studio
- License: mit
- Created: 2023-05-13T17:55:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-11T16:29:30.000Z (about 1 year ago)
- Last Synced: 2024-10-31T18:11:54.394Z (14 days ago)
- Topics: emit, emitter, event, event-emitter, events, javascript-emitter, typescript-emitter
- Language: TypeScript
- Homepage:
- Size: 155 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Codeowners: .github/codeowners
Awesome Lists containing this project
README
# Emitter
A super simple and lightweight event emitter.
Repository | Package | Releases | Discussions
```sh
npm i @hypernym/emitter
```## Features
- TypeScript friendly
- Fully tree-shakeable
- No dependencies## Usage
### JS
```js
import { createEmitter } from '@hypernym/emitter'const emitter = createEmitter()
emitter.on('event-id', (e) => console.log(e.x, e.y))
emitter.emit('event-id', { x: 0, y: 0 })
```### TS
```ts
import { createEmitter, type Emitter } from '@hypernym/emitter'type Events = {
'event-id': { x: number; y: number }
// ...
}const emitter: Emitter = createEmitter()
emitter.on('event-id', (e) => console.log(e.x, e.y))
emitter.emit('event-id', { x: 0, y: 0 })
```## API
### .on()
Registers a specific event.
```ts
emitter.on(id: string, callback: (event: any) => void)
```### .emit()
Emits a specific event.
```ts
emitter.emit(id: string, event: any)
```### .events
Main events map.
Stores all registered events.
```ts
emitter.events
```### .has()
Checks if a specific event by `id` exists in the map.
```ts
emitter.events.has(id: string)
```### .get()
Gets a specific event by `id` from the map.
```ts
emitter.events.get(id: string)
```### .delete()
Deletes a specific event by `id` from the map.
```ts
emitter.events.delete(id: string)
```### .clear()
Removes all events from the map.
```ts
emitter.events.clear()
```## Community
Feel free to use the official [discussions](https://github.com/hypernym-studio/emitter/discussions) for any additional questions.
## License
Developed in ðŸ‡ðŸ‡· Croatia
Released under the [MIT](LICENSE.txt) license.
© Hypernym Studio