💧EventEmitter's typesafe replacement💧
Home - Documentation - v2.0 🚀
--- `'evt'` is intended to be a replacement for `'events'`. It enables and encourages **functional programming** and 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) ) - ✅ Lightweight, no dependency. - ✅ Can be imported with `require` (CJS) or `import` (ESM) as long as you install [`evt@beta`](https://github.com/garronej/evt/pull/16) - ✅ [React Hooks integration](https://stackblitz.com/edit/evt-react-hooks-todo-list?file=index.tsx) Can be imported in TypeScript projects using version >= **3.4** \(Mar 2019\) and in any plain JS projects. # TL;DR* ```typescript import { Evt } from "evt"; const evtText = new Evt# 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: * RxJS introduces a lot of abstractions. It's a big jump from ``EventEmitter``. * With RxJS It is often needed to resort to custom [type guards](https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards), the filter operator [breaks the type inference.](https://stackblitz.com/edit/evt-795plc?embed=1&file=index.ts&hideExplorer=1) * RxJS tends to be quite verbose. * It could be months before RxJS it eventually supports Deno. * No official guideline on how to integrate RxJS with React. EVT is an attempt to address all these points while trying to remain as accessible as `EventEmitter`. [Get started](https://docs.evt.land/overview#rxjs-comparison) # The sticker