EVT
Search…
Evt.asNonPostable(evt)
Evt.asNonPostable() is the identity function with special type annotation
Return the passed evt typed as an object that can't be posted.

Usecase:

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:
1
import { Evt } from "evt";
2
3
//Return an event that post every second.
4
function generateEvtTick(delay: number) {
5
6
const evtTick= Evt.create(0);
7
8
setInterval(()=> evtTick.state++, delay);
9
10
retrun Evt.asNonPostable(evtTick);
11
12
}
13
14
const evtTick= generateTick(1000);
15
16
17
evtTick.state++; // TS ERROR
18
evtTick.post(2); // TS ERROR
Copied!
Last modified 1yr ago
Copy link
Contents
Usecase: