All Projects → garronej → Evt

garronej / Evt

Licence: mit
💧EventEmitter's typesafe replacement

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Evt

Await Of
await wrapper for easier errors handling without try-catch
Stars: ✭ 240 (-21.31%)
Mutual labels:  promise, async-await, browser
Kitsu
🦊 A simple, lightweight & framework agnostic JSON:API client
Stars: ✭ 166 (-45.57%)
Mutual labels:  promise, async-await
Unityfx.async
Asynchronous operations (promises) for Unity3d.
Stars: ✭ 143 (-53.11%)
Mutual labels:  promise, async-await
Popsicle
Simple HTTP requests for node and the browser
Stars: ✭ 238 (-21.97%)
Mutual labels:  promise, browser
Ws Wrapper
Lightweight WebSocket lib with socket.io-like event handling, requests, and channels
Stars: ✭ 58 (-80.98%)
Mutual labels:  promise, browser
Simple Fs
Handles files on indexeddb like you would do in node.js (promise)
Stars: ✭ 111 (-63.61%)
Mutual labels:  promise, browser
Foy
A simple, light-weight and modern task runner for general purpose.
Stars: ✭ 157 (-48.52%)
Mutual labels:  promise, async-await
retryx
Promise-based retry workflow library.
Stars: ✭ 21 (-93.11%)
Mutual labels:  promise, async-await
of
🍬 Promise wrapper with sugar 🍬
Stars: ✭ 13 (-95.74%)
Mutual labels:  promise, async-await
conquerant
lightweight async/await for Clojure
Stars: ✭ 31 (-89.84%)
Mutual labels:  promise, async-await
Await Handler
Basic wrapper for await that allows handling of errors without try/catch blocks
Stars: ✭ 13 (-95.74%)
Mutual labels:  promise, async-await
arraync
Async Array methods polyfills
Stars: ✭ 16 (-94.75%)
Mutual labels:  promise, async-await
Then
🎬 Tame async code with battle-tested promises
Stars: ✭ 908 (+197.7%)
Mutual labels:  promise, async-await
Rubico
[a]synchronous functional programming
Stars: ✭ 133 (-56.39%)
Mutual labels:  promise, async-await
P Map
Map over promises concurrently
Stars: ✭ 639 (+109.51%)
Mutual labels:  promise, async-await
Posterus
Composable async primitives with cancelation, control over scheduling, and coroutines. Superior replacement for JS Promises.
Stars: ✭ 536 (+75.74%)
Mutual labels:  promise, async-await
Basic Ftp
FTP client for Node.js, supports FTPS over TLS, passive mode over IPv6, async/await, and Typescript.
Stars: ✭ 441 (+44.59%)
Mutual labels:  promise, async-await
Thunks
A small and magical composer for all JavaScript asynchronous.
Stars: ✭ 523 (+71.48%)
Mutual labels:  promise, async-await
eslint-config-welly
😎 ⚙️ ESLint configuration for React projects that I do. Feel free to use this!
Stars: ✭ 21 (-93.11%)
Mutual labels:  promise, async-await
debounce-async
A debounce function that delays invoking asynchronous functions.
Stars: ✭ 21 (-93.11%)
Mutual labels:  promise, async-await

💧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.

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

//Mind the '$' prefixing 'attach'
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]);

in React

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

const evtTick = Evt.create();

setInterval(()=> evtTick.post(), 1000);

function App(){

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

    useEvt(ctx=> {
    
        evtTick.attach(ctx, ()=> setCount(count+1));
    
    },[count]);
    
    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 "https://deno.land/x/evt/mod.ts";

Anywhere else:

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

Import from HTML, with CDN

<script src="//unpkg.com/evt/bundle.min.js"></script>
<script>
    const { Evt } = window["evt"];
</script>

Try it

Run some examples

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, 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

Shop

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].