Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/garronej/evt
💧EventEmitter's typesafe replacement
https://github.com/garronej/evt
async-await browser deno eventemitter node nodejs promise react-native typescript
Last synced: about 2 hours ago
JSON representation
💧EventEmitter's typesafe replacement
- Host: GitHub
- URL: https://github.com/garronej/evt
- Owner: garronej
- License: mit
- Created: 2017-02-13T05:14:38.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-11-18T20:14:39.000Z (24 days ago)
- Last Synced: 2024-12-05T10:55:57.967Z (7 days ago)
- Topics: async-await, browser, deno, eventemitter, node, nodejs, promise, react-native, typescript
- Language: TypeScript
- Homepage: https://evt.land
- Size: 12.6 MB
- Stars: 456
- Watchers: 6
- Forks: 6
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-deno - evt - EventEmitter的类型安全替代品。 (Uncategorized / Uncategorized)
- awesome-list - evt
- awesome-deno-cn - @garronej/evt
- awesome-deno - evt - Type safe replacement for EventEmitter.![GitHub stars](https://img.shields.io/github/stars/garronej/evt?style=plastic) (Modules / Online Playgrounds)
- awesome-deno - evt - Type safe replacement for EventEmitter. (Modules / Utils)
README
💧EventEmitter's typesafe replacement💧
---
`'evt'` is intended to be a replacement for `'events'`.
It makes heavy use of **typescript**'s type inference features to provide **type safety** while keeping things **concise and elegant** 🍸.Suitable for any JS runtime env (deno, node, old browsers, react-native ...)
- ✅ It is both a [Deno](https://deno.land/x/evt) and an [NPM](https://www.npmjs.com/evt) module. ( Achieved with [Denoify](https://github.com/garronej/denoify) )
- ✅ No external dependencies ([`tsafe`](https://github.com/garronej/tsafe), [`run-exclusive`](https://github.com/garronej/run_exclusive) and [`minimal-polyfills`](https://github.com/garronej/minimal_polyfills) are all from the same author as EVT).
- ✅ [Makes it easy to work with events in React](https://docs.evt.land/react-hooks).Can be imported in TypeScript projects using version TypeScript >= 3.8 (February 20th, 2020) and in any plain JS projects.
> NOTE: There is very few breaking changes from v1 to v2. [Check them out](https://docs.evt.land/v1-greater-than-v2).
# Who is using it
# Install / Import
## In Deno:
```typescript
import { Evt } from "https://deno.land/x/evt/mod.ts";
```
## Anywhere else:
```bash
$ npm install --save evt
```
```typescript
import { Evt } from "evt";
```# Try it
# Motivations
There are a lot of things that can't easily be done with `EventEmitter`:
* Enforcing **type safety**.
* Removing a particular listener ( if the callback is an anonymous function ).
* Adding a one-time listener for the next event that meets a condition.
* Waiting \(via a Promise\) for one thing or another to happen.
_Example: waiting at most one second for the next message, stop waiting if the socket disconnects._Why would someone pick EVT over RxJS:
* EVT's learning curve is not as steep as RxJS's.
* Generates code that is easier to grasp for people not familiar with reactive programming.EVT is an attempt to address all these points while trying to remain as accessible as `EventEmitter`.
# The sticker