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.asNonPostable(evt)

PreviousEvt.asPostable(evt)NextEvt.setDefaultMaxHandlers(n)

Last updated 2 years ago

Evt.asNonPostable() is the identity function with special type annotation

Return the passed evt typed as an object that can't be posted.

Usecase:

Take .

You could use this function to enforce that the return type by inferred and save you the trouble of having to import the StatefulReadonlyEvt interface:

import { Evt } from "evt";

//Return an event that post every second.
function generateEvtTick(delay: number) {

    const evtTick= Evt.create(0);

    setInterval(()=> evtTick.state++, delay);

    retrun Evt.asNonPostable(evtTick);

}

const evtTick= generateTick(1000);


evtTick.state++; // TS ERROR
evtTick.post(2); // TS ERROR
📖
this example