EVT
HomeGitHub
v1
v1
  • Why EVT ?
  • Overview
  • API Documentation
    • Evt<T>
      • evt.attach*(...)
      • evt.post*(data)
      • evt.waitFor(...)
      • evt.evt[Attach|Detach]
      • evt.pipe(...)
      • evt.getHandlers()
      • evt.isHandled(data)
      • evt.detach(ctx?)
      • evt.enableTrace(...)
      • evt.setMaxHandlers(n)
      • toStateful(initialState)
      • evt.getStatelessOp(op)
      • Evt.create(initalState?)
      • Evt.newCtx<T>()
      • Evt.getCtx(object)
      • Evt.from<T>(...)
      • Evt.merge([ evt1, evt2, ... ])
      • Evt.loosenType(evt)
      • Evt.factorize(evt)
      • Evt.asPostable(evt)
      • Evt.asNonPostable(evt)
      • Evt.setDefaultMaxHandlers(n)
    • Ctx<T>
    • Operator<T, U> (type)
    • StatefulEvt<T>
    • Helper types
    • Handler<T, U> (type)
  • React hooks
  • Extending Evt
Powered by GitBook
On this page

Why EVT ?

NextOverview

Last updated 2 years ago

'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 browser, react-native ...)

  • ✅ It is both a and an module.

  • ✅ 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.

Motivation

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.

  • Tend to be quite verbose.

  • It could be months before it eventually supports Deno.

  • There is no official guideline on how to integrate it with React.

EVT is an attempt to build a lib as accessible as the EventEmitter yet much more powerfull.

It is often needed to resort to custom , the filter operator

type guards
breaks the type inference.
Deno
NPM
React Hooks integration