💧EventEmitter's typesafe replacement💧
'evt' is intended to be a replacement for
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 and an NPM module. ( Achieved with Denoify )
- ✅ Lightweight, no dependency.
- ✅ No polyfills needed, the NPM module is transpiled down to ES3
Can be imported in TypeScript projects using version >= 3.4 (Mar 2019) and in any plain JS projects.
;;;evtText.attachconsole.logtext;evtTime.attachOnceconsole.logtime;evtText.post"hi!"; //Prints "hi!"evtTime.post123; //Prints "123"evtTime.post1234; //Prints nothing
;|>;//Mind the '$' prefixing 'attach'evt.$attachto"text", console.logtext;evt.$attachOnceto"time", console.logtime;evt.post;evt.post;evt.post;
*Those are introductory examples, EVT can do much more than this.
Who is using it
Install / Import
$ npm install --save evt
Import from HTML, with CDN
There are a lot of things that can't easily be done with
- 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.
- It introduces a lot of abstractions. It's a big jump from
- It is often needed to resort to custom type guards, the filter operator breaks the type inference.
- Tend to be quite verbose.
- It could be months before it eventually supports Deno.
EVT is an attempt to address all these points while trying to remain as accessible as