StatefulEvt<T>

A StatefulEvt is an Evt stat keep a reference to the last value posted.

You can think of it as way to observe when a value is changed.

When you attach to a StatefulEvt the callback is immediately called with the current value (except with attachExtract and attachOnceExtract).

.state

Property type: T

reading the property gives the last event data posted. Setting the property (evt.state = data) is equivalent to calling .post(data).

.pipe(...)

Same as evt.pipe(...) but return a StatefulEvt. Be aware that the current state of the StatefulEvt must be matched by the operator ( if any ) when invoking .pipe(), elst an exception will be thrown.

Converting an Evt into a StatefulEvt

Basic example:

Concrete example:

onlyIfChanged operator

When using stetefull Evt is often usefull to have event posted only when the state value has changed. For that purpose you can pipe with the onlyIfChanged operator.

Concrete example:

If we take the previous example:

Now if we put the onlyIfChanged operator intor the mix:

Merging multiple StatefulEvts

****Run the example****

Make a StatefulEvt readonly

To prevent a StatefulEvt to be posted by parts of the code that is not supposed to StatefulEvt can be exposed as StatefulReadonlyEvt.

.toStateless([ctx])

Return a stateless copy of the Evt.

evt.toStateless() is equivalent to Evt.prototype.pipe.call(evt)

Last updated