developit / developit/mitt

Support for `.once()` API

Open
#136 20 comments 48 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
11.9k
Forks
488
PR merge metrics
No merged PRs in 30d

Description

**Motivation**
I believe this is quite common use-case where you have to listen for an even only once (for example, module getting `ready`). The library does not support this inherently but could easily be done with some wiring. This would open up a new use-case support as well as users of the library does not have to write boilerplates on their own.

**Example Usage**
```ts
const emitter: mitt.Emitter = new mitt();

emitter.once('ready', () => console.log("Called Once");

emitter.emit('ready'); // Log: Called Once
emitter.emit('ready'); // No side effect
```

@developit I would love to know your opinion on this.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.