Awesome Open Source
Awesome Open Source

💧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 and an NPM module. ( Achieved with Denoify )
  • ✅ Lightweight, no dependency.
  • ✅ No polyfills needed, the NPM module is transpiled down to ES3
  • React Hooks integration

Can be imported in TypeScript projects using version >= 3.4 (Mar 2019) and in any plain JS projects.


import { Evt } from "evt";

const evtText = new Evt<string>();
const evtTime = new Evt<number>();

evtText.attach(text => console.log(text));
evtTime.attachOnce(time => console.log(time));"hi!"); //Prints "hi!";   //Prints "123";  //Prints nothing


import { Evt, to } from "evt";

const evt = new Evt<
    [ "text",  string ] | 
    [ "time",  number ]

//Mind the '$' prefixing 'attach'
evt.$attach(to("text"), text => console.log(text));
evt.$attachOnce(to("time"), time => console.log(time));["text", "hi!"]);["time", 123]);["time", 1234]);

in React

import { useState } from "react";
import { Evt } from "evt";
import { useEvt } from "evt/hooks";

const evtTick = Evt.create();

setInterval(()=>, 1000);

function App(){

    const [count, setCount]= useState(0);

    useEvt(ctx=> {
        evtTick.attach(ctx, ()=> setCount(count+1));
    return <h1>tick count: {count}</h1>;


run it

*Those are introductory examples, EVT can do much more than this.

Who is using it

Install / Import

In Deno:

import { Evt } from "";

Anywhere else:

$ npm install --save evt
import { Evt } from "evt"; 

Import from HTML, with CDN

<script src="//"></script>
    const { Evt } = window["evt"];

Try it

Run some examples


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, the filter operator breaks the type inference.
  • 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

The sticker


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
typescript (10,447
nodejs (3,639
react-native (1,473
node (952
browser (436
promise (200
deno (108
async-await (86

Find Open Source By Browsing 7,000 Topics Across 59 Categories