New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

evt

Package Overview
Dependencies
Maintainers
1
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

evt

Type safe replacement for node's EventEmitter

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
52K
increased by0.46%
Maintainers
1
Weekly downloads
 
Created
Source

💧Type safe replacement for Node's EventEmitter💧

Home - Documentation


'evt' is intended to be a replacement for 'events'.
It enable and encourage functional programming and makes heavy use of typescript's type inference features to provide type safety while keeping things concise and elegant 🍸.

Browserify friendly:

  • No polyfills needed ✅
  • Transpiled down to ES3 ✅
  • Light-weight, no dependencies ✅

TL;DR*

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));

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

OR

import { Evt, to } from "evt";

const evt = new Evt<
    [ "text",  string ] | 
    [ "time",  number ]
>();

evt.$attach(to("text"), text => console.log(text));
evt.$attachOnce(to("time"), time => console.log(time));

evt.post(["text", "hi!"]);
evt.post(["time", 123]);
evt.post(["time", 1234]);

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

Try it

Run some examples

Motivation

There are a lot of things that can't easily be done with EventEmitter:

  • Enforcing type safety.
  • Removing a particular listener when 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.

Concerning RxJS:

EVT is an attempt to solve all these issues while trying to remain as accessible as EventEmitter.


Get started

Keywords

FAQs

Package last updated on 30 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc