For the complete documentation index, see llms.txt. This page is also available as Markdown.

Evt.asPostable(evt)

Cast the passed event as portable.

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

To invoke post() on a NonPostableEvt or a StatefullReadonlyEvt.

Usecase:

Without this method this would be the way for a class to expose Evt that are posted internally and exposed to be listened.

import { Evt } from "evt";

class Socket2 {

    private readonly _evtIsConnected= Evt.create(false);
    private readonly _evtMessage= Evt.create<Uint8Array>();

    readonly evtIsConnected= Evt.asNonPostable(this._evtIsConnected);
    readonly evtMessage= Evt.asNonPostable(this._evtMessage);

    /* 
        OR, more explicit but require to repeat the types and to
        import type { StatefulReadonlyEvt, NonPostableEvt } from "evt";

    readonly evtIsConnected: StatefulReadonlyEvt<boolean>= this._evtIsConnected;
    readonly evtMessage: NonPostableEvt<Uint8Array> = this._evtMessage;
    */

    constructor(){

        this._evtIsConnected.state = true;
        this._evtMessage.post(new Uint8Array(111));

    }

}

Now it can be frustrating to have to store a private property only to call post on a object that we know is postable. Here is were this method come in handy:

Last updated