Overview

EventEmitter comparison

Let us consider this example, use of EventEmitter:

import { EventEmitter } from "events";

const eventEmitter = new EventEmitter();

eventEmitter.on("text", text => console.log(text));
eventEmitter.once("time", time => console.log(time));

eventEmitter.emit("text", "hi!"); //Prints "hi!"
eventEmitter.emit("time", 123); //Prints "123"
eventEmitter.emit("time", 1234); //Prints nothing ( once )

In EVT the recommended approach is to give every event it's Evt instance. Translation of the example:

import { Evt } from "evt";
//Or import { Evt } from "https://evt.land/x/evt/mod.ts" on deno

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

evtText.attach(text => console.log(text));
evtTime.attachOnce(time => console.log(time));

evtText.post("hi!");
evtTime.post(123);
evtTime.post(1234);

However, the traditional approach that consists of gathering all the events in a single bus is also an option.

Note: Due to a current TypeScript limitation the .attach() methods need to be prefixed with $ when used with fλ ( to in this case) operators but evt.$attach*() are actually just aliases to the corresponding evt.attach*() methods.

Run the example

RxJS comparison

"Get started" examples.

Here is a translations of the examples provided as an overview on the RxJS website.

****Run the example

RxJS operators vs EVT operator

Unlike RxJS operators that return Observable EVT operators are function build using native language features, no by composing other pre-existing operators or instantiating any particular class.

Consider that we have an emitter for this data type:

We want to get a Promise<string> that resolves with the next text event.

****Run the example****

Let us consider another example involving state encapsulation. Here we want to accumulate all texts events until "STOP"

****Run the example****

Where to start

The API reference documentation is full of runnable examples that should get you started in no time.

Last updated