EVT
GitHubHomePlaygroud
v2
v2
  • 🚀EVT Overview
  • 📖API Documentation
    • Evt<T>
      • Async iterator
      • 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
  • 🔩From EventEmitter to Evt
  • ⬆️v1 -> v2
Powered by GitBook
On this page
Edit on GitHub
  1. API Documentation
  2. Evt<T>

Evt.factorize(evt)

This is the identity function with special type annotations.

If you have a variable that is either an Evt that post A or an Evt that post B you have an event that post A or B.

In other words Evt<A> | Evt<B> is assignable to Evt<A | B >. This method implements this property.

import { Evt, VoidEvt, matchVoid } from "evt";

declare evt: Evt<string> | Evt<number> | VoidEvt = Evt.create<any>();

evt.attach(data=> { }); // TS ERROR

Evt.factorize(evt) // OK, return Evt<string | number | void>
    .attach(data=> { // data is string | number | void

        //To test if data is void
        if( matchVoid(data) ){
            return;
        }

        //Here data is string | number.

    })
    ;
PreviousEvt.loosenType(evt)NextEvt.asPostable(evt)

Last updated 2 years ago

See also , helper type that this method levrage.

📖
FactorizeEvt<E>